<template>
  <!--
    	作者：offline
    	时间：2018-09-12
    	描述：实物对账单申请tabs页组件(订单信息、入库详情)
  -->
  <div
    class="m-view-physicalApplyComponents m-window"
    id="phyApp"
    v-loading="formLoading"
  >
    <el-form
      ref="headerRuleForm"
      label-width="60px"
      :inline-message="true"
      label-position="left"
      class="m-headerForm"
    >
      <el-row :gutter="10">
        <el-col
          v-if="accountBtnShow && rollBtnAuth"
          :span="2"
          class="m-floatRight"
        >
          <el-button type="primary" @click="rollbackPhyData" :disabled="btnDis"
            >退回</el-button
          >
        </el-col>
        <el-col
          v-if="accountBtnShow && confirmBtnAuth"
          :span="2"
          class="m-floatRight"
        >
          <el-button type="primary" @click="confirmPhyData" :disabled="btnDis"
            >确认</el-button
          >
        </el-col>
        <el-col
          v-if="supplierBtnShow && submitBtnShow"
          :span="2"
          class="m-floatRight"
        >
          <el-popover
            placement="top-start"
            title="提示"
            width="260"
            trigger="hover"
            content="【提交】:单据会提交到联塑公司"
          >
            <el-button
              type="primary"
              @click="submitPhyData"
              :disabled="btnDis"
              slot="reference"
              >提交</el-button
            >
          </el-popover>
        </el-col>
        <el-col :span="2" v-if="saveBtnShow && isSave" class="m-floatRight">
          <el-popover
            placement="top-start"
            title="提示"
            width="200"
            trigger="hover"
            content="【保存】：单据只会暂存在本地"
          >
            <el-button
              type="primary"
              @click="savePhyData"
              :disabled="btnDis"
              slot="reference"
              >保存</el-button
            >
          </el-popover>
        </el-col>
        <el-col :span="2" v-if="reConBtnShow" class="m-floatRight">
          <el-button type="primary" @click="reConfirm" :disabled="btnDis"
            >反确认</el-button
          >
        </el-col>
        <el-col :span="2" class="m-floatRight">
          <el-button
            @click="cancel"
            :disabled="btnDis"
            v-if="pageLayOut !== 'add'"
            >返回</el-button
          >
        </el-col>
        <el-col :span="2" class="m-floatRight">
          <el-button
            @click="closePage"
            :disabled="btnDis"
            v-if="pageLayOut == 'add'"
            >关闭</el-button
          >
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="6">
          <el-form-item
            label="实物对账单号"
            class="rightItem"
            label-width="100px"
          >
            <el-input
              v-model="phyCode"
              placeholder="实物对账单号"
              clearable
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="7" v-if="accountType == 1 && pageLayOut == 'add'">
          <el-form-item label="供应商" class="rightItem">
            <el-select
              filterable
              clearable
              v-model="supplierCode"
              placeholder="请选择供应商"
              @focus="focusMethod"
              @clear="supplierOptions = allSupplier"
              @change="supplierChange"
              :filter-method="filterSupplier"
            >
              <el-option
                v-for="item in supplierOptions"
                :key="item.id"
                :label="item.supplierName"
                :value="item.supplierCode"
              >
                <span style="float: left">{{ item.supplierName }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">{{
                  item.supplierCode
                }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7" v-else>
          <el-form-item label="供应商" class="rightItem">
            <el-input
              v-model="supplierName"
              placeholder="供应商"
              clearable
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="7" v-if="optionShow">
          <el-form-item
            :label="accountType == 1 ? '公司' : '客户'"
            class="rightItem"
          >
            <el-select
              value-key="id"
              v-model="selCompanyCode"
              :placeholder="`请选择${accountType == 1 ? '公司' : '客户'}`"
              @change="companyChange"
              ref="content"
              clearable
            >
              <el-option
                v-for="item in comOptions"
                :key="item.companyCode"
                :label="item.companyName"
                :value="item"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7" v-if="labelShow">
          <el-form-item label="客户" class="rightItem">
            <el-input v-model="customer" placeholder="客户" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="7" v-if="companyLabelShow">
          <el-form-item label="公司" class="rightItem">
            <el-input v-model="comName" placeholder="公司" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4" v-if="optionShow">
          <el-form-item label="对账类型" class="rightItem" label-width="70px">
            <el-select
              v-model="selAccountCode"
              placeholder="对账类型"
              @change="typeChange"
              clearable
            >
              <el-option
                v-for="item in typeOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4" v-if="typeShow">
          <el-form-item label="对账类型" class="rightItem" label-width="70px">
            <el-input v-model="selAccountType" placeholder disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="6">
          <el-form-item label="申请日期" class="rightItem" label-width="100px">
            <el-date-picker
              v-model="applyDate"
              type="date"
              placeholder="申请日期"
              value-format="yyyy-MM-dd HH:mm:ss"
              disabled
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="14">
          <el-form-item label="备注" label-width="60px" class="rightItem">
            <el-input
              placeholder="请输入备注(可编辑200字)"
              v-model="remark"
              maxlength="200"
              :disabled="inputDis"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4" v-if="btnShow" class="m-floatright-col">
          <el-button type="primary" @click="importPhysical"
            >引入入库记录</el-button
          >
        </el-col>
      </el-row>
      <el-row :gutter="5"> </el-row>
    </el-form>
    <div class="m-total">
      <span>
        对账总金额：
        <samp style="color: red" v-text="billTotalMoney"></samp>元
      </span>
      <span>
        对账总数量：
        <samp style="color: red" v-text="billTotalCount"></samp>
      </span>
    </div>
    <div class="m-mainContent m-top3">
      <el-tabs type="card">
        <el-tab-pane label="入库详情">
          <div class="m-agTable">
            <!--入库单-->
            <ag-grid-component
              ref="phyStorageAgGrid"
              :getColumnDefs="phyStorageColumnDefs"
              :getRowSelection="'multiple'"
              :tableName="'phyStorage'"
              :getGridOptions="phyStorageGridOptions"
              :getRowData="phyStorageRowData"
              :isColFit="true"
              v-loading="loading"
              :systemInfo="$systemInfo"
            ></ag-grid-component>
          </div>
        </el-tab-pane>
        <el-tab-pane label="订单汇总">
          <div class="m-agTable">
            <!--订单-->
            <ag-grid-component
              ref="phyOrderAgGrid"
              :getColumnDefs="phyOrderColumnDefs"
              :getRowSelection="'single'"
              :tableName="'phyOrder'"
              :getGridOptions="phyOrderGridOptions"
              :getRowData="phyOrderRowData"
              :isColFit="true"
              :systemInfo="$systemInfo"
              v-loading="loading"
            ></ag-grid-component>
          </div>
        </el-tab-pane>
        <el-tab-pane
          label="审批意见"
          v-if="pageLayOut != 'add' && signInfo.length > 0"
        >
          <sign-option-tab :signInfo="signInfo"></sign-option-tab>
        </el-tab-pane>
      </el-tabs>
    </div>

    <!--弹框-->
    <el-dialog
      custom-class="m-connetModel"
      title="选择入库记录"
      v-if="storageDialogVisible"
      :visible.sync="storageDialogVisible"
      width="80%"
      v-dialogDrag
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :before-close="handleClose"
    >
      <el-row :gutter="10" class="header-row">
        <el-form
          label-width="70px"
          :inline-message="true"
          label-position="left"
        >
          <el-col :span="10">
            <el-form-item label="供应商" class="rightItem">
              <el-input
                v-model="supplierName"
                placeholder="供应商"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="客户" class="rightItem">
              <el-input
                v-model="selCompanyName"
                placeholder="客户"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="对账类型" class="centerItem">
              <el-input
                v-model="selAccountType"
                placeholder="对账类型"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <el-row :gutter="10" class="header-row">
        <el-form
          label-width="70px"
          :inline-message="true"
          label-position="left"
        >
          <el-col :span="6">
            <el-form-item label="入库日期" class="rightItem">
              <el-date-picker
                v-model="applySDate"
                type="date"
                placeholder="入库开始日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-date-picker
              v-model="applyEDate"
              type="date"
              placeholder="入库结束日期"
              value-format="yyyy-MM-dd"
            ></el-date-picker>
          </el-col>
          <el-col :span="7">
            <el-form-item label="采购单号" class="rightItem">
              <el-input
                v-model="purNo"
                placeholder="输入采购单号"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="入库单号" class="centerItem">
              <el-input
                v-model="instockNo"
                placeholder="输入入库单号"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-button type="primary" @click="search" :disabled="searchDis"
              >查询</el-button
            >
          </el-col>
        </el-form>
      </el-row>
      <el-row>
        <el-col :span="24">入库明细：</el-col>
      </el-row>
      <div class="m-agTableModel" style="height: 280px">
        <ag-grid-vue
          class="m-agTableContent ag-theme-balham"
          :gridOptions="storageInfoOptions"
          :columnDefs="storageInfoColumnDefs"
          :rowData="storageInfoRowData"
          v-loading="diaLoading"
          rowSelection="multiple"
        ></ag-grid-vue>
      </div>
      <el-row>
        <el-col :span="22">待选明细：</el-col>
        <el-col :span="2">
          <el-button @click="addStandByRows">添加</el-button>
        </el-col>
      </el-row>
      <div class="m-agTableModel">
        <ag-grid-vue
          class="m-agTableContent ag-theme-balham"
          :gridOptions="standbyInfoOptions"
          :columnDefs="standbyInfoColumnDefs"
          :rowData="standbyInfoRowData"
        ></ag-grid-vue>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelDialog">取消</el-button>
        <el-button type="primary" @click="saveStandbyData">保存</el-button>
      </span>
    </el-dialog>

    <!--差异说明-->
    <el-dialog
      custom-class="m-connetModel"
      title="差异说明"
      v-if="difInfoDialogVisible"
      :visible.sync="difInfoDialogVisible"
      width="50%"
      v-dialogDrag
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :before-close="difDialogClose"
    >
      <el-card class="box-card" style="margin-bottom: 10px; width: 100%">
        <div
          v-for="(item, key) in difInfo"
          :key="key"
          class="text item"
          style="margin-bottom: 20px; overflow: hidden"
        >
          <p
            v-if="item.visible"
            style="
              text-align: center;
              font-size: 11px;
              color: gray;
              padding-bottom: 5px;
              overflow: hidden;
              width: 100%;
            "
          >
            {{ item.createDate }}
          </p>
          <span
            v-if="item.visible"
            :style="
              item.isSupSend == 1
                ? 'float:left; text-align:left;'
                : 'float:right; text-align:right;'
            "
            style="width: 80%; display: block"
          >
            <p style="font-size: 12px">{{ item.sender }}</p>
            <p
              style="
                font-size: 12px;
                color: blue;
                text-decoration: underline;
                cursor: pointer;
              "
              @click="downLoadFile(item)"
            >
              {{ item.attachmentName }}
            </p>
            <p style="font-size: 12px">{{ item.content }}</p>
          </span>
        </div>
        <div
          style="text-align: center; line-height: 200px"
          v-if="difInfo.length == 0"
        >
          暂无数据!
        </div>
      </el-card>
      <el-form
        :model="difRuleForm"
        ref="difRuleForm"
        class="demo-ruleForm"
        :rules="difRules"
        v-if="sendShow"
      >
        <el-form-item prop="difDetail" style="margin-bottom: 0">
          <upLoadfile
            :config="fileConfig"
            @fileChange="diffFileChange"
            ref="diffUpload"
          ></upLoadfile>
          <el-row :gutter="10">
            <el-col :span="20">
              <el-input
                v-model="difRuleForm.difDetail"
                type="textarea"
                :rows="3"
                placeholder="请输入备注(可编辑100字)"
                maxlength="100"
                resize="none"
              ></el-input>
            </el-col>
            <el-col :span="4">
              <el-button type="primary" @click="sendDifInfo" :disabled="sendBtn"
                >发送</el-button
              >
            </el-col>
          </el-row>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import _Api from "@/api";
import localeText from "@/i18n/agGridText";
import Vue from "vue";
import upLoadfile from "@/components/upLoadFile";
import waterfall from "async-es/waterfall";
import constant from "@/public/constant";
import supplierInfo from "@/public/supplierInfo.js";
import serviceTime from "@/public/serverTime.js";
import downLoadFileFunc from "@/public/downLoadFile.js";
import NumericEditorComponent from "@/components/NumericEditorComponent";
import SignOptionTab from "./common/signOptionTab";
import Msg from "@/public/message.js";
import addOperation from "@/public/addOperation.js";
import gridOptions from "lesso-common/public/gridOptions";
import { formatPrice } from "@/util/format";

const details = Vue.extend({
  //v-if="isOk" v-if = " params.node.data.confirmFlag == 1 ? false : true "
  template: `<span v-if="params.node.data.isTotal == 1 ? false : true">
    <el-button :style=" params.node.data.isMsExist == 1 ? 'color:red' : '' " type="text" @click="details" class="rendererClass" size="mini">差异详情</el-button>
    <el-button type="text" @click="delDetails" class="rendererClass" size="mini" v-if="isOk">删除</el-button>
    <el-button type="text" @click="adjustMoney" class="rendererClass" size="mini" v-if="adShow">金额调整</el-button>
    </span>`,
  data: function () {
    return {
      isOk: details.isOk,
      adShow: details.adShow,
      billState: details.billState,
    };
  },
  methods: {
    details() {
      this.params.context.componentParent.showDifDialog(this.params.node.data); //
    },
    delDetails() {
      this.params.context.componentParent.deleteDetails(this.params.node.data);
    },
    adjustMoney() {
      this.params.context.componentParent.singleAdjustMoney(
        this.params.node.data
      );
    },
  },
  mounted() {
    if (this.$global.user.userTypeId == "4") {
      //供应商
      if (this.billState > 1) this.isOk = false;
      else if (this.billState == 1) {
        if (this.params.node.data.confirmFlag === 1) this.isOk = false;
        else {
          if (this.params.node.data.isSupSend === 1) this.isOk = true;
          else if (this.params.node.data.isSupSend === 2) this.isOk = false;
          else if (this.params.node.data.isSupSend == null) this.isOk = true;
        }
      }
    } else if (this.$global.user.userTypeId != "4") {
      //非供应商
      if (this.params.node.data.id) this.isOk = false;
      else this.isOk = true;
    }
  },
});

export default {
  data() {
    return {
      searchDis: false,
      normalSize: true,
      typeShow: false,
      typeOptions: [
        { value: 0, label: "材料类" },
        { value: 1, label: "费用类" },
      ],
      accountType: this.$global.user.userTypeId,
      selAccountType: "",
      selAccountCode: "",
      supplierBtnShow: true,
      accountBtnShow: false,
      activeName: "first",
      phyOrderColumnDefs: [],
      phyOrderRowData: [],
      phyStorageColumnDefs: [],
      phyStorageRowData: [],
      loading: false,
      diaLoading: false,
      phyCode: "",
      selCompanyCode: "",
      selCompanyName: "",
      comOptions: [],
      supplierName: "",
      remark: "",
      signOption: "", //签字意见
      storageDialogVisible: false,
      customer: "",
      applyDate: "",
      applySDate: "",
      applyEDate: "",
      orderInfoColumnDefs: [],
      orderInfoRowData: [],
      storageInfoColumnDefs: [],
      storageInfoRowData: [],
      standbyInfoColumnDefs: [],
      standbyInfoRowData: [],
      supplierCode: "",
      orderSelRows: [],
      storageSelRows: [],
      sumOrderRows: [],
      sumStorageRows: [],
      purNo: "",
      instockNo: "",
      optionShow: true,
      labelShow: false,
      selConfiguration: "single", //multiple
      difInfoDialogVisible: false,
      difRuleForm: {
        difDetail: "",
      },
      difRules: {
        difDetail: [
          {
            min: 0,
            max: 100,
            trigger: "change",
            message: "长度在100个字符",
          },
        ],
      },
      difInfo: [],
      diffFileSize: "",
      upload_url: "",
      fileList: [],
      difDetailInfo: {}, //保存上传文件信息
      clickRowData: {}, //当前点击行详细属性
      comName: "",
      companyLabelShow: false,
      btnShow: true,
      saveBtnShow: true,
      deleteShow: true,
      sendShow: true,
      adjustShow: false,
      inputDis: false,
      isOk: true,
      supplierInfo: "",
      getClickDetailInfo: {},
      phyBillState: "",
      billTotalMoney: 0,
      billTotalCount: 0,
      billTotalAdjust: 0,
      selBillTotalMoney: 0,
      selBillTotalCount: 0,
      selBillTotalAdjust: 0,
      selectedRows: [],
      serviceTime: "",
      standBySelectedRows: [], //备选数组
      tempSelectedRows: [], //临时数组
      mxId: "", //明细ID
      btnDis: false,
      rows: [], //保存没有id的数据
      supplierSend: 0, //供应商发送
      accountSend: 0, //应付人员发送
      sendBtn: false,
      getClickRowIndex: 0, //当前点击行的rowIndex
      dialogSize: document.body.clientWidth,
      htmlElement: "",
      reConBtnShow: false,
      isSave: false,
      submitBtnShow: false,
      rollBtnAuth: false,
      confirmBtnAuth: false,
      userInfo: {
        userName: this.$global.user.employeeName,
        userId: this.$global.user.id,
        groupName: "SRM",
      },
      //   审批意见相关
      signInfo: [],
      // 根据公司权限获取供应商数据
      supplierOptions: [],
      // 本地保存所有权限供应商
      allSupplier: [],
      formLoading: false,
      //  上传组件相关配置
      fileConfig: {
        limits: 1,
        accept: ".pdf,.doc,.docx,.xls,.xlsx,.txt",
        maxSize: 20971520,
        multiple: true,
      },
    };
  },
  beforeMount() {
    var that = this;
    this.phyOrderGridOptions = Object.assign(
      {
        context: {
          componentParent: this,
        },
        enableColResize: true,
        localeText: localeText,
        onSelectionChanged: this.phyOrderRowSelected,
        //   onRowClicked: this.phyOrderRowClicked,
        navigateToNextCell: this.myNavigation,
        suppressRowClickSelection: true,
        suppressMenuHide: true,
        enableFilter: true, //列过滤器
        enableSorting: true, //列排序
        animateRows: true, //排序动画
        postProcessPopup: function (params) {
          if (params.type != "columnMenu") return;
          that.htmlElement = params.eventSource;
        },
      },
      gridOptions({
        dragSelectCheckbox: true,
        singleSelection: true,
        operation: true,
      })
    );
    this.phyStorageGridOptions = Object.assign(
      {
        context: {
          componentParent: this,
        },
        enableColResize: true,
        suppressRowClickSelection: true,
        localeText: localeText,
        suppressMenuHide: true,
        enableFilter: true, //列过滤器
        enableSorting: true, //列排序
        animateRows: true, //排序动画
        singleClickEdit: true,
        pinnedBottomRowData: this.createData(1, "Bottom"),
        getContextMenuItems: this.getContextMenuItems,
        //          onCellClicked: this.phyStorageSelected,
        // rowMultiSelectWithClick: true,
        onRowEditingStarted: function (event) {},
        onRowEditingStopped: function (event) {},
        onCellEditingStarted: function (event) {},
        onCellEditingStopped: function (event) {},
        components: {
          singleClickEditRenderer: singleClickEditRenderer,
          disConfirm: disConfirm,
          isConfirm: isConfirm,
          isZero: isZero,
          customPinnedRowRenderer: CustomPinnedRowRenderer,
        },
        getRowStyle: function (params) {
          if (params.node.rowPinned) {
            return { color: "red", "font-weight": "bold" };
          }
          if (params.data.isMsExist == "1") {
            return { color: "red" };
          }
        },
      },
      gridOptions({
        dragSelectCheckbox: true,
        singleSelection: true,
        operation: true,
      })
    );
    this.phyOrderColumnDefs = [
      {
        headerName: "采购订单号",
        field: "purOrdNo",
        width: 130,
        menuTabs: ["filterMenuTab"],
        headerCheckboxSelection: true,
        headerCheckboxSelectionFilteredOnly: true,
        filter: "agTextColumnFilter",
      }, // filter: ''  filterComponents
      { headerName: "订单行号", field: "purOrdMxNo", width: 90, menuTabs: [] },
      { headerName: "物料号", field: "matCode", width: 100 },
      {
        headerName: "物料描述",
        field: "matName",
        width: 150,
        menuTabs: [],
        tooltipField: "matName",
      },
      {
        headerName: "订单数量",
        field: "orderAmount",
        hide: true,
        menuTabs: [],
      },
      { headerName: "期间入库数量", field: "amount", hide: true, menuTabs: [] },
      {
        headerName: "对账金额",
        field: "selMoney",
        width: 120,
        menuTabs: [],
        cellRenderer: function (params) {
          if (params.value)
            return params.value
              .toString()
              .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
          else return params.value;
        },
      },
      {
        headerName: "对账入库数量",
        field: "selAmount",
        width: 120,
        menuTabs: [],
        cellRenderer: function (params) {
          if (params.value)
            return params.value
              .toString()
              .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
          else return params.value;
        },
      },
      { headerName: "单位", field: "unitCode", width: 70, menuTabs: [] },
      {
        headerName: "单价",
        field: "unitPrice",
        width: 100,
        menuTabs: [],
        cellRenderer: function (params) {
          if (params.value)
            return params.value
              .toString()
              .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
          else return params.value;
        },
      },
      { headerName: "合计金额", field: "realMoney", hide: true },
    ];

    this.phyStorageColumnDefs = [
      { headerName: "id", field: "id", hide: true },
      {
        headerName: "采购订单号",
        field: "purOrdNo",
        width: 130,
        menuTabs: [],
        filter: "agTextColumnFilter",
      },
      {
        headerName: "订单行号",
        field: "purOrdMxNo",
        width: 90,
        menuTabs: [],
        filter: "agNumberColumnFilter",
      },
      { headerName: "物料号", field: "matCode", width: 100, menuTabs: [] },
      {
        headerName: "物料描述",
        field: "matName",
        width: 160,
        menuTabs: [],
        tooltipField: "matName",
      },
      {
        headerName: "入库单号",
        field: "instockNo",
        width: 120,
        hide: false,
        menuTabs: [],
      },
      {
        headerName: "入库日期",
        field: "postDate",
        sort: "asc",
        width: 110,
        menuTabs: [],
        cellRenderer: function (params) {
          if (params.value)
            return new Date(Date.parse(params.value.replace(/-/g, "/"))).Format(
              "yyyy-MM-dd"
            );
        },
      },
      {
        headerName: "入库数量",
        field: "amount",
        width: 100,
        menuTabs: [],
        cellRenderer: function (params) {
          if (params.value)
            return params.value
              .toString()
              .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
          else return params.value;
        },
      },
      { headerName: "单位", field: "unitCode", width: 80, menuTabs: [] },
      {
        headerName: "价格数量",
        field: "priceAmount",
        width: 100,
        menuTabs: [],
        cellRenderer: function (params) {
          if (params.value)
            return params.value
              .toString()
              .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
          else return params.value;
        },
      },
      { headerName: "价格单位", field: "priceUnit", width: 100, menuTabs: [] },
      {
        headerName: "含税单价",
        field: "unitPrice",
        width: 100,
        menuTabs: [],
        cellRenderer: function (params) {
          if (params.value) {
         
            if (params.value != null) {
              if (params.value.indexOf(".") != 0) {
                let strArr = params.value.split(".");
                let unitPriceValue = Number(strArr[0]);
                let formatOne = unitPriceValue
                  .toString()
                  .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
                let lastValue = formatOne + "." + strArr[1];
              
                return lastValue;
              }
            }
          } else {
            return params.value;
          }
        },
      },
      {
        headerName: "含税金额",
        field: "realMoney",
        width: 100,
        menuTabs: [],
        cellRenderer: function (params) {
          if (params.value)
            return params.value
              .toString()
              .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
          else return params.value;
        },
      },
      {
        headerName: "差异金额",
        field: "adjustMoney",
        width: 100,
        editable: false,
        cellEditorFramework: NumericEditorComponent,
        onCellValueChanged: this.cellValueChanged,
        menuTabs: [],
      },
      {
        headerName: "金额合计",
        field: "sumMoney",
        width: 100,
        cellRenderer: function (params) {
          if (!params.node.rowPinned) {
            const { realMoney, adjustMoney } = params.node.data;
            let total = addOperation.accAdd(realMoney, adjustMoney);
            return (params.value = total
              .toString()
              .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"));
          } else {
            return params.value;
          }
        },
        menuTabs: [],
      },
      {
        headerName: "操作",
        field: "adjust",
        width: 130,
        cellRendererFramework: details,
        menuTabs: [],
        hide: false,
        pinned: "right",
      },
      {
        headerName: "确认",
        field: "confirmFlag",
        width: 80,
        pinned: "right",
        menuTabs: [],
        hide: false,
        cellRendererSelector: function (params) {
          var singleClickEditRenderer = {
            component: "singleClickEditRenderer",
          };
          var disConfirm = {
            component: "disConfirm",
          };
          var isConfirm = {
            component: "isConfirm",
          };
          var isZero = {
            component: "isZero",
          };
          //供应商
          if (constant.user.userTypeId === 4 && params.data.isSupSend === 1) {
            if (params.data.isMsExist === 1 && params.data.confirmFlag === 0)
              return disConfirm;
            else if (
              params.data.isMsExist === 1 &&
              params.data.confirmFlag === 1
            )
              return isConfirm;
            else if (param.data.isMsExist === 0) return isZero;
            else return null;
          } else if (
            constant.user.userTypeId === 4 &&
            params.data.isSupSend === 2
          ) {
            if (params.data.isMsExist === 1 && params.data.confirmFlag === 0)
              return singleClickEditRenderer;
            else if (
              params.data.isMsExist === 1 &&
              params.data.confirmFlag === 1
            )
              return isConfirm;
            else if (params.data.isMsExist === 0) return isZero;
            else return null;
          } else if (constant.user.userTypeId === 4 && !params.data.isSupSend) {
            return isZero;
          }
          //非供应商
          if (constant.user.userTypeId !== 4 && params.data.isSupSend === 1) {
            if (params.data.isMsExist === 1 && params.data.confirmFlag === 0)
              return singleClickEditRenderer;
            else if (
              params.data.isMsExist === 1 &&
              params.data.confirmFlag === 1
            )
              return isConfirm;
            else if (params.data.isMsExist === 0) return isZero;
            else return isZero;
          } else if (
            constant.user.userTypeId !== 4 &&
            params.data.isSupSend === 2
          ) {
            if (params.data.isMsExist === 1 && params.data.confirmFlag === 0)
              return disConfirm;
            else if (
              params.data.isMsExist === 1 &&
              params.data.confirmFlag === 1
            )
              return isConfirm;
            else if (params.data.isMsExist === 0) return isZero;
            else return isZero;
          } else if (constant.user.userTypeId !== 4 && !params.data.isSupSend) {
            return isZero;
          }
        },
        valueGetter: function (params) {
          //供应商
          if (constant.user.userTypeId === 4 && params.data.isSupSend === 1) {
            if (params.data.isMsExist === 1 && params.data.confirmFlag === 0)
              return disConfirm;
            else if (
              params.data.isMsExist === 1 &&
              params.data.confirmFlag === 1
            )
              return isConfirm;
            else if (param.data.isMsExist === 0) return isZero;
            else return null;
          } else if (
            constant.user.userTypeId === 4 &&
            params.data.isSupSend === 2
          ) {
            if (params.data.isMsExist === 1 && params.data.confirmFlag === 0)
              return singleClickEditRenderer;
            else if (
              params.data.isMsExist === 1 &&
              params.data.confirmFlag === 1
            )
              return isConfirm;
            else if (params.data.isMsExist === 0) return isZero;
            else return null;
          } else if (constant.user.userTypeId === 4 && !params.data.isSupSend) {
            return isZero;
          }
          //非供应商
          if (constant.user.userTypeId !== 4 && params.data.isSupSend === 1) {
            if (params.data.isMsExist === 1 && params.data.confirmFlag === 0)
              return singleClickEditRenderer;
            else if (
              params.data.isMsExist === 1 &&
              params.data.confirmFlag === 1
            )
              return isConfirm;
            else if (params.data.isMsExist === 0) return isZero;
            else return isZero;
          } else if (
            constant.user.userTypeId !== 4 &&
            params.data.isSupSend === 2
          ) {
            if (params.data.isMsExist === 1 && params.data.confirmFlag === 0)
              return disConfirm;
            else if (
              params.data.isMsExist === 1 &&
              params.data.confirmFlag === 1
            )
              return isConfirm;
            else if (params.data.isMsExist === 0) return isZero;
            else return isZero;
          } else if (constant.user.userTypeId !== 4 && !params.data.isSupSend) {
            return isZero;
          }
        },
      },
      {
        headerName: "入库行号",
        field: "instockMxNo",
        width: 90,
        hide: true,
        menuTabs: [],
      },
    ];
    this.orderInfoOptions = {
      context: {
        componentParent: this,
      },
      enableColResize: true,
      localeText: localeText,
      suppressRowClickSelection: true,
    };
    this.storageInfoOptions = {
      context: {
        componentParent: this,
      },
      enableColResize: true,
      localeText: localeText,
      rowMultiSelectWithClick: true,
      //          onRowSelected:this.storageInfoSelected,
      onRowSelected: this.storageInfoSel,
      enableFilter: true, //列过滤器
      enableSorting: true, //列排序
      animateRows: true, //排序动画
      suppressRowClickSelection: true,
    };
    //订单详情
    //      this.orderInfoColumnDefs = [
    //          { headerName: "采购订单号", field: "purOrdNo",width:100 },
    //          { headerName: "订单行号", field: "purOrdMxNo", width: 100 },
    //          { headerName: "物料号", field: "matCode", width: 150 },
    //          { headerName: "物料描述", field: "matName", width: 250 },
    //          { headerName: "订单数量", field: "orderAmount", width: 100 },
    //          { headerName: "期间入库数量", field: "amount", width: 120 },
    //          { headerName: "勾选入库数量", field: "selAmount", width: 120 },
    //          { headerName: "单位", field: "unitCode", width: 100 },
    //          { headerName: "订单单价", field: "unitPrice", width: 100 },
    //          { headerName: "合计金额", field: "realMoney", width: 100 },
    //          { headerName: "勾选金额", field: "selMoney", width: 100 },
    //          { headerName: "退货", field: "retFlag", width: 150 }
    //      ];
    //入库详情
    this.storageInfoColumnDefs = [
      {
        headerName: "采购订单号",
        field: "purOrdNo",
        checkboxSelection: true,
        width: 130,
        headerCheckboxSelection: true,
        headerCheckboxSelectionFilteredOnly: true,
      },
      { headerName: "订单行号", field: "purOrdMxNo", width: 90 },
      {
        headerName: "入库日期",
        field: "postDate",
        sort: "asc",
        width: 110,
        cellRenderer: function (params) {
          if (params.value) {
            return new Date(Date.parse(params.value.replace(/-/g, "/"))).Format(
              "yyyy-MM-dd"
            );
          }
        },
      },

      { headerName: "物料号", field: "matCode", width: 100 },
      { headerName: "物料描述", field: "matName", width: 250 },
      { headerName: "入库数量", field: "amount", width: 100 },
      { headerName: "单位", field: "unitCode", width: 100 }, //
      { headerName: "金额", field: "realMoney", width: 100 },
      { headerName: "差异金额", field: "adjustMoney", width: 100 },
      { headerName: "合计金额", field: "sumMoney", width: 100 },
      { headerName: "价格数量", field: "priceAmount", width: 100 }, //jjc
      { headerName: "价格单位", field: "priceUnit", width: 100 }, //jjc
      { headerName: "入库单号", field: "instockNo", width: 100 },
      { headerName: "入库行号", field: "instockMxNo", width: 100 },
      { headerName: "实物对账状态", field: "flag", width: 100, hide: true },
    ];
    //待选
    this.standbyInfoOptions = {
      context: {
        componentParent: this,
      },
      enableColResize: true,
      localeText: localeText,
      enableFilter: true, //列过滤器
      enableSorting: true, //列排序
      animateRows: true, //排序动画
      suppressRowClickSelection: true,
    };
    this.standbyInfoColumnDefs = [
      {
        headerName: "序号",
        width: 90,
        sort: "asc",
        cellRenderer: function (params) {
          return parseInt(params.node.id) + 1;
        },
      },
      { headerName: "采购订单号", field: "purOrdNo", width: 130 },
      { headerName: "订单行号", field: "purOrdMxNo", width: 90 },
      {
        headerName: "入库日期",
        field: "postDate",
        width: 100,
        cellRenderer: function (params) {
          if (params.value) {
            return new Date(Date.parse(params.value.replace(/-/g, "/"))).Format(
              "yyyy-MM-dd"
            );
          }
        },
      },
      { headerName: "物料号", field: "matCode", width: 100 },
      { headerName: "物料描述", field: "matName", width: 250 },
      { headerName: "入库数量", field: "amount", width: 100 },
      { headerName: "单位", field: "unitCode", width: 100 },
      { headerName: "金额", field: "realMoney", width: 100 },
      { headerName: "差异金额", field: "adjustMoney", width: 100 },
      { headerName: "合计金额", field: "sumMoney", width: 100 },
      { headerName: "价格数量", field: "priceAmount", width: 100 },
      { headerName: "价格单位", field: "priceUnit", width: 100 },
      { headerName: "入库单号", field: "instockNo", width: 100 },
      { headerName: "入库行号", field: "instockMxNo", width: 90 },
    ];

    document.onkeydown = function (e) {
      let evn = e || event;
      let key = evn.keyCode || evn.which || evn.charCode;
      if (key === 116 && that.phyCode == "") {
        that.getPhysicalNo();
      } else if (e.ctrlKey && key === 70) {
        // that.$refs.phyStorageAgGrid.gridOptions.api.hidePopupMenu();
        // if(that.$refs.phyStorageAgGrid.gridOptions.api && that.htmlElement != "")
        //     that.$refs.phyStorageAgGrid.gridOptions.api.showColumnMenuAfterButtonClick("purOrdNo",that.htmlElement);
      }
    };
  },
  watch: {
    dialogSize(val) {
      this.dialogSize = val;
      this.$nextTick((_) => {
        // that.$refs.phyStorageAgGrid.gridOptions.api.sizeColumnsToFit();
      });
    },
    billTotalMoney() {
      this.billTotalMoney = this.billTotalMoney
        .toString()
        .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
    },
    billTotalCount() {
      this.billTotalCount = formatPrice(this.billTotalCount, 4);
    },
    billTotalAdjust() {
      this.billTotalAdjust = this.billTotalAdjust
        .toString()
        .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
    },
  },
  created() {},
  methods: {
    // 差异文件变化
    diffFileChange(files) {
      console.log(files);
      this.difDetailInfo = {
        orgName: files[0].name,
        fileName: files[0].url,
        fileSize: files[0].size,
      };
    },
    // 获取当前公司所有供应商
    getAuthSuppliers(companyCode) {
      this.formLoading = true;
      this.supplierCode = "";
      this.$http
        .getAuthSupplierByCompanyCode({ name: companyCode })
        .then(({ data }) => {
          this.formLoading = false;
          if (data.code == 1) {
            this.supplierOptions = data.rows;
            this.allSupplier = data.rows;
          } else {
            Msg.showErrorMsg(data.info);
          }
        })
        .catch((err) => {
          this.formLoading = false;
          Msg.showErrorMsg(err.data.message);
        });
    },
    // 筛选供应商
    filterSupplier(value) {
      if (value != "") {
        this.supplierOptions = this.allSupplier.filter(
          (item) =>
            item.supplierCode.indexOf(value) > -1 ||
            item.supplierName.indexOf(value) > -1
        );
      } else {
        this.supplierOptions = this.allSupplier;
      }
    },
    // 供应商下拉框获取焦点
    focusMethod() {
      if (!this.selCompanyCode) {
        Msg.showPopMsg("请先选择公司!");
        this.$refs.content.focus();
      }
    },
    // 供应商选择框下拉
    supplierChange(val) {
      for (let i = 0; i < this.supplierOptions.length; i++) {
        if (val == this.supplierOptions[i].supplierCode) {
          this.supplierName = this.supplierOptions[i].supplierName;
          return;
        }
      }
    },
    reConfirm() {
      var that = this;
      this.$prompt("审批意见", "消息提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        customClass: "promitBox",
        inputType: "textarea",
        distinguishCancelAndClose: true,
      })
        .then(({ value }) => {
          var obj = {
            gooAccNo: that.setClickValue.gooAccNo,
            modifyer: this.$global.user.employeeName,
            modifyerId: this.$global.user.id,
            signOption: value,
          };
          that.btnDis = true;
          _Api
            .phyReconfirm(obj)
            .then(function (response) {
              that.btnDis = false;
              var data = response.data;
              if (data.code == "1") {
                Msg.showSuccessMsg("操作成功");
                that.cancel();
              } else {
                that.$alert("操作失败！：" + data.info, {
                  showClose: false,
                  confirmButton: "确定",
                  customClass: "alertFailure",
                });
              }
            })
            .catch((err) => {
              that.btnDis = false;
              Msg.showErrorMsg(err.data.message);
            });
        })
        .catch(() => {});
    },
    getBtnAuth() {
      var that = this;
      var obj = {
        resultType: "0",
        code: "goodsAccountBill",
        authClientCode: constant.authCode.code,
        authTenantCode: constant.authCode.tcode,
      };
      _Api
        .getUserAuthMenu(obj)
        .then(function (response) {
          var data = response.data;
          if (data.code == "1") {
            if (data.total > 0) {
              for (let i in data.rows) {
                if (that.pageLayOut == "edit") {
                  if (
                    data.rows[i].code == "reConfirm" &&
                    that.setClickValue.billState == 3
                  ) {
                    that.reConBtnShow = true;
                  }
                }
                if (data.rows[i].code == "goodAccountSave") {
                  that.isSave = true;
                }
                if (data.rows[i].code == "goodAccountSubmit") {
                  that.submitBtnShow = true;
                }
                if (
                  data.rows[i].code == "goodAccountRollback" &&
                  that.pageLayOut == "edit"
                ) {
                  that.rollBtnAuth = true;
                }
                if (
                  data.rows[i].code == "goodAccountConfirm" &&
                  that.pageLayOut == "edit"
                ) {
                  that.confirmBtnAuth = true;
                }
              }
            } else {
              that.reConBtnShow = false;
              that.isSave = false;
              that.submitBtnShow = false;
              that.rollBtnAuth = false;
              that.confirmBtnAuth = false;
            }
          }
        })
        .catch((err) => {
          Msg.showErrorMsg(err.data.message);
        });
    },
    getContextMenuItems() {
      //右击菜单
      //   if (this.pageLayOut == "add") {
      //     return [];
      //   }
      var that = this;
      var result = [
        {
          name: "导出Excel",
          action: function () {
            that.exportExcel();
          },
        },
      ];
      return result;
    },
    exportExcel() {
      //导出设置
      var params = {
        fileName: "实物对账明细导出.xls",
        columnKeys: [
          "purOrdNo",
          "purOrdMxNo",
          "matCode",
          "matName",
          "postDate",
          "amount",
          "realMoney",
          "adjustMoney",
          "instockNo",
          "instockMxNo",
        ],
      };
      this.$refs.phyStorageAgGrid.gridOptions.api.exportDataAsExcel(params);
    },
    myNavigation(params) {
      var previousCell = params.previousCellDef;
      var suggestedNextCell = params.nextCellDef;

      var KEY_UP = 38;
      var KEY_DOWN = 40;
      var KEY_LEFT = 37;
      var KEY_RIGHT = 39;

      switch (params.key) {
        case KEY_DOWN:
          previousCell = params.previousCellDef;
          // set selected cell on current cell + 1
          this.$refs.phyOrderAgGrid.gridOptions.api.forEachNode((node) => {
            if (previousCell.rowIndex + 1 === node.rowIndex) {
              node.setSelected(true);
            }
          });
          return suggestedNextCell;
        case KEY_UP:
          previousCell = params.previousCellDef;
          // set selected cell on current cell - 1
          this.$refs.phyOrderAgGrid.gridOptions.api.forEachNode((node) => {
            if (previousCell.rowIndex - 1 === node.rowIndex) {
              node.setSelected(true);
            }
          });
          return suggestedNextCell;
        case KEY_LEFT:
        case KEY_RIGHT:
          return suggestedNextCell;
        default:
          throw "this will never happen, navigation is always on of the 4 keys above";
      }
    },
    retractSize() {
      this.normalSize = false;
    },
    openSize() {
      this.normalSize = true;
    },
    companyChange(value) {
      if (
        this.orderSelRows.length <= 0 &&
        this.storageSelRows.length <= 0 &&
        value != ""
      ) {
        if (value.companyCode != "") {
          for (var i = 0; i < this.comOptions.length; i++) {
            if (value.companyCode == this.comOptions[i].companyCode) {
              this.selCompanyName = this.comOptions[i].companyName;
              if (this.accountType == 1 && this.pageLayOut == "add")
                this.getAuthSuppliers(value.companyCode);
              return;
            }
          }
        } else {
          this.selCompanyName = "";
        }
      } else {
        this.selCompanyName = "";
        this.orderSelRows = [];
        this.storageSelRows = [];
        this.$refs.phyOrderAgGrid.gridOptions.api.setRowData([]);
        this.$refs.phyStorageAgGrid.gridOptions.api.setRowData([]);
      }
    },
    typeChange(value) {
      if (
        this.orderSelRows.length <= 0 &&
        this.storageSelRows.length <= 0 &&
        value !== ""
      ) {
        if (!isNaN(value)) {
          for (var i = 0; i < this.typeOptions.length; i++) {
            if (value == this.typeOptions[i].value) {
              this.selAccountType = this.typeOptions[i].label;
              return;
            }
          }
        }
        //              else {
        //                  this.selAccountType = "";
        //              }
      } else {
        this.selAccountType = "";
        this.orderSelRows = [];
        this.storageSelRows = [];
        this.$refs.phyOrderAgGrid.gridOptions.api.setRowData([]);
        this.$refs.phyStorageAgGrid.gridOptions.api.setRowData([]);
      }
    },
    importPhysical() {
      if (this.pageLayOut == "add") {
        if (!this.phyCode) {
          Msg.showPopMsg("未生成实物对账单号，暂不允许引入操作！");
          return;
        }
        if (this.selAccountCode === "" && !this.selCompanyCode.companyCode) {
          Msg.showPopMsg("请选择对账类型、相关客户！");
          return;
        }
        if (this.selAccountCode === "") {
          Msg.showPopMsg("请选择对账类型！");
          return;
        }
        if (!this.selCompanyCode.companyCode) {
          Msg.showPopMsg("请选择相关客户！");
          return;
        }
        if (this.accountType == 1 && !this.supplierCode) {
          Msg.showPopMsg("请选择供应商！");
          return;
        }
        this.storageDialogVisible = true;
      } else if (this.pageLayOut == "edit") {
        this.selCompanyName = this.setClickValue.companyName;
        this.storageDialogVisible = true;
      }
      for (let i = this.storageSelRows.length - 1; i >= 0; i--) {
        if (this.storageSelRows[i].isTotal) this.storageSelRows.splice(i, 1);
      }
      let that = this;
      setTimeout(() => {
        that.standbyInfoOptions.api.setRowData(that.storageSelRows);
        that.standbyInfoOptions.api.hideOverlay();
        that.storageInfoOptions.api.hideOverlay();
      }, 100);
    },
    deletePhysical() {
      //入库信息勾选
      // var selRows = JSON.parse(JSON.stringify(this.$refs.phyStorageAgGrid.gridOptions.api.getSelectedRows()));
      var selRows = this.$refs.phyStorageAgGrid.gridOptions.api.getSelectedRows();
      var selRows2 = this.$refs.phyOrderAgGrid.gridOptions.api.getSelectedRows();
      //   var tempOrderTable = [];//订单信息临时表
      var that = this;
      if (selRows.length <= 0) {
        Msg.showPopMsg("提示：请选择需要删除的数据");
        return;
      }
      this.$confirm("是否确认删除该数据？", "消息提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        distinguishCancelAndClose: true,
      })
        .then(() => {
          let sum1 = 0; //总数行
          let sum2 = 0; //勾选删除行
          //删除时候要一并删除保存数组的行
          //1、删除保存入库信息的数组
          for (let i = 0; i < selRows.length; i++) {
            for (let j = that.storageSelRows.length - 1; j >= 0; j--) {
              if (
                that.storageSelRows[j].instockNo == selRows[i].instockNo &&
                that.storageSelRows[j].instockMxNo == selRows[i].instockMxNo
              ) {
                that.storageSelRows.splice(j, 1);
              }
            }
          }
          //2、根据当前删除行判断订单信息
          for (let i = 0; i < selRows.length; i++) {
            that.$refs.phyStorageAgGrid.gridOptions.api.forEachNode(function (
              node
            ) {
              if (
                node.data.purOrdNo == selRows[i].purOrdNo &&
                node.data.purOrdMxNo == selRows[i].purOrdMxNo
              )
                sum1++;
              if (
                node.data.purOrdNo == selRows[i].purOrdNo &&
                node.data.purOrdMxNo == selRows[i].purOrdMxNo &&
                node.selected == true
              )
                sum2++;
            });
            if (sum1 > sum2) {
              //改变指定行的值
              let temp = [];
              let sumAmount = 0;
              that.$refs.phyStorageAgGrid.gridOptions.api.forEachNode(function (
                node
              ) {
                if (
                  node.data.purOrdNo == selRows[i].purOrdNo &&
                  node.data.purOrdMxNo == selRows[i].purOrdMxNo &&
                  node.selected == false
                )
                  temp.push(node.data.amount);
              });
              if (temp.length == 1) {
                that.$refs.phyOrderAgGrid.gridOptions.api.forEachNode(function (
                  node
                ) {
                  let rowIndex = that.$refs.phyOrderAgGrid.gridOptions.api.getRowNode(
                    node.rowIndex
                  );
                  if (
                    node.data.purOrdNo == selRows[i].purOrdNo &&
                    node.data.purOrdMxNo == selRows[i].purOrdMxNo
                  )
                    rowIndex.setDataValue("selAmount", temp[0]);
                });
              } else {
                for (let a = temp.length - 1; a >= 0; a--) sumAmount += temp[i];
                that.$refs.phyOrderAgGrid.gridOptions.api.forEachNode(function (
                  node
                ) {
                  let rowIndex = that.$refs.phyOrderAgGrid.gridOptions.api.getRowNode(
                    node.rowIndex
                  );
                  if (
                    node.data.purOrdNo == selRows[i].purOrdNo &&
                    node.data.purOrdMxNo == selRows[i].purOrdMxNo
                  )
                    rowIndex.setDataValue("selAmount", sumAmount);
                });
              }
              //console.log(temp)
            } else if (sum1 == sum2) {
              for (let j = that.orderSelRows.length - 1; j >= 0; j--) {
                if (
                  that.orderSelRows[j].purOrdNo == selRows[i].purOrdNo &&
                  that.orderSelRows[j].purOrdMxNo == selRows[i].purOrdMxNo
                )
                  that.orderSelRows.splice(j, 1);
              }
            }
          }
          //3、调用删除接口
          let id = "";
          for (let i = 0; i < selRows.length; i++) {
            if (selRows[i].id) {
              id += selRows[i].id + ",";
            }
          }
          id = id.substr(0, id.length - 1);
          var obj = {
            id: id,
          };
          if (id.length > 0) {
            _Api
              .deleteGoodsDetails(obj)
              .then(function (response) {
                var data = response.data;
                if (data.code == "1") {
                  console.log(data);
                } else {
                  Msg.showErrorMsg(data.info);
                }
              })
              .catch((err) => {
                Msg.showErrorMsg(err.data.message);
              });
          }
          //4、移除指定行
          that.$refs.phyStorageAgGrid.gridOptions.api.updateRowData({
            remove: selRows,
          });
          that.$refs.phyOrderAgGrid.gridOptions.api.updateRowData({
            remove: selRows2,
          });
          that.$refs.phyOrderAgGrid.gridOptions.api.setRowData(
            that.orderSelRows
          );
        })
        .catch(() => {});
    },
    saveData() {
      // this.orderSelRows = this.orderInfoOptions.api.getSelectedRows();
      // this.storageSelRows = this.storageInfoOptions.api.getSelectedRows();
      if (this.orderSelRows.length <= 0 || this.storageSelRows.length <= 0) {
        Msg.showPopMsg("提示：选择需要保存的数据！");
        return;
      }
      this.applySDate = "";
      this.applyEDate = "";
      this.orderInfoOptions.api.setRowData([]);
      this.storageInfoOptions.api.setRowData([]);
      this.storageDialogVisible = false;

      this.$refs.phyOrderAgGrid.gridOptions.api.setRowData(this.orderSelRows);
      //   let allColumnIds = [];
      //   this.$refs.phyOrderAgGrid.gridOptions.columnApi.getAllColumns().forEach(function (column) {
      //     allColumnIds.push(column.colId);
      //   });
      //jjc20181220 注释
      //this.$refs.phyOrderAgGrid.gridOptions.columnApi.autoSizeColumns(allColumnIds);

      this.billTotalMoney = 0;
      this.billTotalCount = 0;
      for (let i = 0; i < this.storageSelRows.length; i++) {
        this.billTotalMoney = this.accAdd(
          this.billTotalMoney,
          this.storageSelRows[i].realMoney
        );
        this.billTotalCount = this.accAdd(
          this.billTotalCount,
          this.storageSelRows[i].amount
        );
        //              this.billTotalMoney += this.storageSelRows[i].realMoney;
        //              this.billTotalCount += this.storageSelRows[i].amount;
      }

      //加入统计行
      for (let i = this.storageSelRows.length - 1; i >= 0; i--) {
        if (this.storageSelRows[i].isTotal) this.storageSelRows.splice(i, 1);
      }
      //          let obj = {};//合计行
      //          obj.amount = 0;
      //          obj.realMoney = 0;
      //          for(let i = 0; i < this.storageSelRows.length;i++){
      //          	obj.matName = "合计";
      //          	obj.amount = this.accAdd(obj.amount,this.storageSelRows[i].amount);
      //          	obj.realMoney = this.accAdd(obj.realMoney,this.storageSelRows[i].realMoney);
      //          	obj.isTotal = 1;
      //          }
      //          this.storageSelRows.push(obj);
      this.$refs.phyStorageAgGrid.gridOptions.api.setRowData(
        this.storageSelRows
      );
      //   let allColumnIds1 = [];
      //   this.$refs.phyStorageAgGrid.gridOptions.columnApi.getAllColumns().forEach(function (column) {
      //     allColumnIds1.push(column.colId);
      //   });
      //jjc20181220 注释
      //this.$refs.phyStorageAgGrid.gridOptions.columnApi.autoSizeColumns(allColumnIds);
      //          console.log(this.billTotalMoney);
      //          console.log(this.billTotalCount);
    },
    getAuthInfo() {
      //获取当前账号权限公司
      var obj = {};
      var that = this;
      if (this.$global.user.userTypeId == 4) {
        obj.account = this.$global.user.userName;
        obj.userType = 2;
        obj.flag = 1;
      } else if (this.$global.user.userTypeId == 1) {
        obj.account = this.$global.user.oaNum;
        obj.userType = 1;
        obj.flag = 1;
      }
      _Api
        .getAuthInfo(obj)
        .then(function (response) {
          var data = response.data;
          if (data.code == "1") {
            that.comOptions = data.rows.myMstCompany;
          } else {
            that.comOptions = [];
          }
        })
        .catch((err) => {
          Msg.showErrorMsg(err.data.message);
          that.comOptions = [];
        });
    },
    search() {
      if (!this.instockNo && !this.purNo) {
        if (
          (this.applySDate == null || this.applySDate == "") &&
          (this.applyEDate == null || this.applyEDate == "")
        ) {
          this.$alert("请选择日期段！", {
            showClose: false,
            confirmButtonText: "确定",
            customClass: "alertPrompt",
          });
          return;
        }
      }
      var obj = {};
      if (this.$global.user.userTypeId == "4") {
        obj.SupplierCode = this.supplierInfo[0].supplierCode; //this.supplierCode,
        obj.CompanyCode = this.selCompanyCode.companyCode;
        obj.Begin_time = this.applySDate;
        obj.End_time = this.applyEDate;
        obj.type = this.selAccountCode;
      } else {
        obj.type = this.selAccountCode;
        obj.Begin_time = this.applySDate;
        obj.End_time = this.applyEDate;
        if (this.pageLayOut == "add") {
          obj.SupplierCode = this.supplierCode;
          obj.CompanyCode = this.selCompanyCode.companyCode;
        } else {
          obj.SupplierCode = this.setClickValue.supplierCode;
          obj.CompanyCode = this.setClickValue.companyCode;
        }
      }
      //          var obj = {
      //              SupplierCode: this.supplierInfo[0].supplierCode,//this.supplierCode,
      //              CompanyCode: this.selCompanyCode.companyCode,
      //              Begin_time: this.applySDate,
      //              End_time: this.applyEDate
      //          };

      if (this.applySDate != "" && this.applySDate != null) {
        obj.Begin_time = this.applySDate;
        if (this.applyEDate == "" || this.applyEDate == null)
          obj.End_time = obj.Begin_time;
      }
      if (this.applyEDate != "" && this.applyEDate != null) {
        obj.End_time = this.applyEDate;
        if (this.applySDate == "" || this.applySDate == null)
          obj.Begin_time = obj.End_time;
      }
      if (obj.Begin_time != "" && obj.End_time != "") {
        if (obj.Begin_time > obj.End_time) {
          this.$alert("提示：开始日期不能大于结束日期", {
            showClose: false,
            confirmButtonText: "确定",
            customClass: "alertPrompt",
          });
          return;
        }
      }

      if (this.purNo != "") obj.purOrdNo = this.purNo;
      if (this.instockNo != "") obj.instockNo = this.instockNo;
      var that = this;
      this.diaLoading = true;
      this.searchDis = true;
      _Api
        .getStorageInfo(obj)
        .then(function (response) {
          var data = response.data;
          that.searchDis = false;
          if (data.code == "1") {
            //订单信息
            //that.orderInfoRowData = data.rows.m_StorageTotal.splice(0);//that.orderInfoRowData
            //                  that.orderInfoOptions.api.setRowData(data.rows.m_StorageTotal.splice(0));
            //                  for(let i = 0;i<that.orderSelRows.length;i++){
            //                      that.orderInfoOptions.api.forEachNode(function(node){
            //                          if(node.data.purOrdNo == that.orderSelRows[i].purOrdNo && node.data.purOrdMxNo == that.orderSelRows[i].purOrdMxNo)
            //                              node.setSelected(true);
            //                      })
            //                  }
            //                  let allColumnIds = [];
            //					that.orderInfoOptions.columnApi.getAllColumns().forEach(function(column) {
            //						allColumnIds.push(column.colId);
            //					});
            //					that.orderInfoOptions.columnApi.autoSizeColumns(allColumnIds);
            //入库详情
            //that.storageInfoRowData = data.rows.m_StorageDetail.splice(0);
            //                  that.storageInfoOptions.api.setRowData(data.rows.m_StorageDetail.splice(0));
            //                  for(let i = 0;i<that.storageSelRows.length;i++){
            //                      that.storageInfoOptions.api.forEachNode(function(node){
            //                          if(node.data.instockNo == that.storageSelRows[i].instockNo && node.data.instockMxNo == that.storageSelRows[i].instockMxNo)
            //                              node.setSelected(true);
            //                      })
            //                  }
            //                  let allColumnIds1 = [];
            //					that.storageInfoOptions.columnApi.getAllColumns().forEach(function(column) {
            //						allColumnIds1.push(column.colId);
            //					});
            //					that.storageInfoOptions.columnApi.autoSizeColumns(allColumnIds1);
            //设置勾选(新改动) 20181016
            that.storageInfoOptions.api.setRowData(
              data.rows.m_StorageDetail.splice(0)
            );
            for (let i = 0; i < that.tempSelectedRows.length; i++) {
              that.storageInfoOptions.api.forEachNode(function (node) {
                if (
                  node.data.instockNo == that.tempSelectedRows[i].instockNo &&
                  node.data.instockMxNo == that.tempSelectedRows[i].instockMxNo
                ) {
                  node.setSelected(true);
                }
              });
            }
            //   let allColumnIds = [];
            //   that.storageInfoOptions.columnApi.getAllColumns().forEach(function (column) {
            //     allColumnIds.push(column.colId);
            //   });
            //jjc20181220 注释
            //that.storageInfoOptions.columnApi.autoSizeColumns(allColumnIds);
          }
          that.diaLoading = false;
        })
        .catch((err) => {
          Msg.showErrorMsg(err.data.message);
          that.orderInfoOptions.api.setRowData([]);
          that.storageInfoOptions.api.setRowData([]);
          that.diaLoading = false;
          that.searchDis = false;
        });
    },
    getSupplierInfoByMainAccount() {
      var obj = {
        mainAccount: this.$global.user.userName,
      };
      var that = this;
      _Api.getSupplierDetailByAccount(obj).then(function (response) {
        var data = response.data;
        if (data.code == "1") {
          if (data.total == 1) {
            if (data.rows) {
              that.supplierCode = data.rows[0].supplierCode;
            }
          }
        }
      });
    },
    handleClose(done) {
      //          this.applyDate = "";
      this.applySDate = "";
      this.applyEDate = "";
      // this.orderSelRows = [];
      // this.storageSelRows = [];
      //          this.orderInfoOptions.api.setRowData([]);
      this.storageInfoOptions.api.setRowData([]);
      done();
    },
    orderInfoSelected(row) {
      var purOrdNo = row.data.purOrdNo;
      var purOrdMxNo = row.data.purOrdMxNo;
      var that = this;
      var checkAmount = 0;
      var rowNode = this.orderInfoOptions.api.getRowNode(row.rowIndex);
      if (this.storageInfoRowData.length > 0) {
        if (row.node.selected) {
          this.orderInfoOptions.api.forEachNode(function (node) {
            if (
              node.data.purOrdNo == purOrdNo &&
              node.data.purOrdMxNo == purOrdMxNo
            ) {
              node.setSelected(true);
              that.orderSelRows.push(node.data);
            }
          });
          this.storageInfoOptions.api.forEachNode(function (node) {
            if (
              node.data.purOrdNo == purOrdNo &&
              node.data.purOrdMxNo == purOrdMxNo
            ) {
              node.setSelected(true);
              that.storageSelRows.push(node.data);
              checkAmount += node.data.amount;
            }
          });
          rowNode.setDataValue("selAmount", checkAmount);
        } else {
          this.orderInfoOptions.api.forEachNode(function (node) {
            if (
              node.data.purOrdNo == purOrdNo &&
              node.data.purOrdMxNo == purOrdMxNo
            ) {
              node.setSelected(false);
              for (var i = that.orderSelRows.length - 1; i >= 0; i--) {
                if (
                  that.orderSelRows[i].purOrdNo == node.data.purOrdNo &&
                  that.orderSelRows[i].purOrdMxNo == node.data.purOrdMxNo
                ) {
                  that.orderSelRows.splice(i, 1);
                }
              }
            }
          });
          this.storageInfoOptions.api.forEachNode(function (node) {
            if (
              node.data.purOrdNo == purOrdNo &&
              node.data.purOrdMxNo == purOrdMxNo
            ) {
              node.setSelected(false);
              for (var i = that.storageSelRows.length - 1; i >= 0; i--) {
                if (
                  that.storageSelRows[i].purOrdNo == node.data.purOrdNo &&
                  that.storageSelRows[i].purOrdMxNo == node.data.purOrdMxNo
                ) {
                  checkAmount += that.storageSelRows[i].amount;
                  that.storageSelRows.splice(i, 1);
                }
              }
            }
          });
          rowNode.setDataValue(
            "selAmount",
            rowNode.data.selAmount - checkAmount
          );
        }
      }
    },
    storageInfoSelected(row) {
      var instockNo = row.data.instockNo; //入库单号
      var that = this;
      if (row.node.selected == true) {
        //入库详情勾选状态
        this.storageInfoOptions.api.forEachNode(function (node) {
          if (node.data.instockNo == instockNo) {
            node.setSelected(true);
          }
          let purOrdNo = node.data.purOrdNo; //采购订单号
          let purOrdMxNo = node.data.purOrdMxNo; //订单行号
          that.orderInfoOptions.api.forEachNode(function (node1) {
            //订单信息勾选状态
            if (
              node1.data.purOrdNo == purOrdNo &&
              node1.data.purOrdMxNo == purOrdMxNo &&
              node.selected == true
            ) {
              node1.setSelected(true);
            }
          });
        });
        let selRows = JSON.parse(
          JSON.stringify(this.storageInfoOptions.api.getSelectedRows())
        );
        //去除重复项
        for (let i = 0; i < selRows.length; i++) {
          for (let j = 0; j < selRows.length; j++) {
            if (j != i) {
              if (
                selRows[i].purOrdNo == selRows[j].purOrdNo &&
                selRows[i].purOrdMxNo == selRows[j].purOrdMxNo
              ) {
                selRows[i].amount = selRows[i].amount + selRows[j].amount; //汇总项
                selRows[i].realMoney = that.accAdd(
                  selRows[i].realMoney,
                  selRows[j].realMoney
                );
                selRows.splice(j, 1);
              }
            }
          }
        }
        this.orderInfoOptions.api.forEachNode(function (node) {
          let rowNode = that.orderInfoOptions.api.getRowNode(node.rowIndex);
          rowNode.setDataValue("selAmount", 0);
          rowNode.setDataValue("selMoney", 0);
          for (let i = 0; i < selRows.length; i++) {
            if (
              node.data.purOrdNo == selRows[i].purOrdNo &&
              node.data.purOrdMxNo == selRows[i].purOrdMxNo
            ) {
              rowNode.setDataValue("selAmount", selRows[i].amount);
              rowNode.setDataValue("selMoney", selRows[i].realMoney);
            }
          }
        });
        //存入指定数组--订单信息
        let selOrderRows = JSON.parse(
          JSON.stringify(this.orderInfoOptions.api.getSelectedRows())
        );
        for (let i = 0; i < this.orderSelRows.length; i++) {
          selOrderRows.push(this.orderSelRows[i]);
        }
        //去除重复行
        for (let i = 0; i < selOrderRows.length; i++) {
          for (let j = 0; j < selOrderRows.length; j++) {
            if (i != j) {
              if (
                selOrderRows[i].purOrdNo == selOrderRows[j].purOrdNo &&
                selOrderRows[i].purOrdMxNo == selOrderRows[j].purOrdMxNo
              ) {
                selOrderRows.splice(j, 1);
              }
            }
          }
        }
        for (let i = 0; i < selOrderRows.length; i++) {
          for (let j = 0; j < selOrderRows.length; j++) {
            if (i != j) {
              if (
                selOrderRows[i].purOrdNo == selOrderRows[j].purOrdNo &&
                selOrderRows[i].purOrdMxNo == selOrderRows[j].purOrdMxNo
              ) {
                selOrderRows[i].selMoney =
                  selOrderRows[i].selMoney + selOrderRows[j].selMoney;
                selOrderRows.splice(j, 1);
              }
            }
          }
        }
        this.orderSelRows = selOrderRows;
        //存入指定数组--入库详情
        let selStorageRows = JSON.parse(
          JSON.stringify(this.storageInfoOptions.api.getSelectedRows())
        );
        for (let i = this.storageSelRows.length - 1; i >= 0; i--) {
          if (!this.storageSelRows[i].id) {
            this.storageSelRows.splice(i, 1);
          }
        }
        if (this.pageLayOut == "edit") {
          for (let i = 0; i < this.storageSelRows.length; i++) {
            selStorageRows.push(this.storageSelRows[i]);
          }
        }
        this.storageSelRows = selStorageRows;
      } else if (row.node.selected == false) {
        //入库详情取消勾选状态
        this.$confirm("是否取消勾选该数据？", "消息提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          distinguishCancelAndClose: true,
        })
          .then(() => {
            //确定取消勾选状态
            that.storageInfoOptions.api.forEachNode(function (node) {
              if (node.data.instockNo == instockNo) {
                node.setSelected(false);
              }
            });
            //当前选择行
            let selRows = JSON.parse(
              JSON.stringify(that.storageInfoOptions.api.getSelectedRows())
            );
            //订单信息勾选状态
            that.orderInfoOptions.api.forEachNode(function (node) {
              node.setSelected(false);
              for (let i = 0; i < selRows.length; i++) {
                if (
                  node.data.purOrdNo == selRows[i].purOrdNo &&
                  node.data.purOrdMxNo == selRows[i].purOrdMxNo
                ) {
                  node.setSelected(true);
                }
              }
            });
            //去除重复项
            for (let i = 0; i < selRows.length; i++) {
              for (let j = 0; j < selRows.length; j++) {
                if (j != i) {
                  if (
                    selRows[i].purOrdNo == selRows[j].purOrdNo &&
                    selRows[i].purOrdMxNo == selRows[j].purOrdMxNo
                  ) {
                    selRows[i].amount = selRows[i].amount + selRows[j].amount; //汇总项
                    selRows[i].realMoney = that.accAdd(
                      selRows[i].realMoney,
                      selRows[j].realMoney
                    );
                    selRows.splice(j, 1);
                  }
                }
              }
            }
            //指定行赋值
            that.orderInfoOptions.api.forEachNode(function (node) {
              let rowNode = that.orderInfoOptions.api.getRowNode(node.rowIndex);
              rowNode.setDataValue("selAmount", 0);
              rowNode.setDataValue("selMoney", 0);
              for (let i = 0; i < selRows.length; i++) {
                if (
                  node.data.purOrdNo == selRows[i].purOrdNo &&
                  node.data.purOrdMxNo == selRows[i].purOrdMxNo
                ) {
                  rowNode.setDataValue("selAmount", selRows[i].amount);
                  rowNode.setDataValue("selMoney", selRows[i].realMoney);
                }
              }
            });
            //取消勾选时在已选的数组中删除指定数据--入库详情
            if (that.storageSelRows.length > 0) {
              for (let i = that.storageSelRows.length - 1; i >= 0; i--) {
                if (that.storageSelRows[i].instockNo == instockNo)
                  that.storageSelRows.splice(i, 1);
              }
            }
            //取消勾选时在已选数组仲删除指定数据--订单信息
            //1、根据入库单号获取相关采购订单号和订单行号信息
            let tempTable = []; //临时数组
            that.storageInfoOptions.api.forEachNode(function (node) {
              if (node.data.instockNo == instockNo) tempTable.push(node.data);
            });
            //2、取消勾选时在已选数组仲删除指定数据--订单信息
            if (tempTable.length > 0) {
              for (let i = 0; i < tempTable.length; i++) {
                for (let j = that.orderSelRows.length - 1; j >= 0; j--) {
                  if (
                    tempTable[i].purOrdNo == that.orderSelRows[j].purOrdNo &&
                    tempTable[i].purOrdMxNo == that.orderSelRows[j].purOrdMxNo
                  )
                    that.orderSelRows.splice(j, 1);
                }
              }
            }
            //3、根据当前选择行添加到数组
            let tempTableForSelRows = JSON.parse(
              JSON.stringify(that.orderInfoOptions.api.getSelectedRows())
            );
            if (tempTableForSelRows.length > 0) {
              for (let i = 0; i < tempTableForSelRows.length; i++) {
                that.orderSelRows.push(tempTableForSelRows[i]);
              }
            }
            //4、去除重复行
            for (let i = 0; i < that.orderSelRows.length; i++) {
              for (let j = 0; j < that.orderSelRows.length; j++) {
                if (i != j) {
                  if (
                    that.orderSelRows[i].purOrdNo ==
                      that.orderSelRows[j].purOrdNo &&
                    that.orderSelRows[i].purOrdMxNo ==
                      that.orderSelRows[j].purOrdMxNo
                  )
                    that.orderSelRows.splice(j, 1);
                }
              }
            }
            //console.log(that.orderSelRows);
          })
          .catch(() => {
            let rowNode = that.storageInfoOptions.api.getRowNode(
              row.node.rowIndex
            );
            that.storageInfoOptions.api.forEachNode(function (node) {
              if (node.rowIndex == rowNode.rowIndex) node.setSelected(true);
            });
          });
      }
    },
    savePhyData() {
      if (this.orderSelRows.length <= 0 || this.storageSelRows.length <= 0) {
        Msg.showPopMsg("提示：请选择需要保存的数据！");
        return;
      }
      for (let i = this.storageSelRows.length - 1; i >= 0; i--) {
        if (this.storageSelRows[i].isTotal) this.storageSelRows.splice(i, 1);
      }
      var that = this;
      var obj = {};
      if (this.$global.user.userTypeId == "4") {
        if (this.pageLayOut == "add") {
          if (this.difInfo.length > 0) {
            for (let i = 0; i < this.storageSelRows.length; i++) {
              this.storageSelRows[i].accountmxmsg = [];
              for (let j = 0; j < this.difInfo.length; j++) {
                let obj = {};
                if (
                  this.difInfo[j].instockNo ==
                    this.storageSelRows[i].instockNo &&
                  this.difInfo[j].instockMxNo ==
                    this.storageSelRows[i].instockMxNo
                ) {
                  obj.content = this.difInfo[j].content;
                  obj.creator = this.$global.user.employeeName;
                  obj.creatorId = this.$global.user.id;
                  obj.modifyer = this.$global.user.employeeName;
                  obj.modifyerId = this.$global.user.id;
                  obj.sender = this.difInfo[j].sender;
                  obj.senderId = this.difInfo[j].senderId;
                  obj.greadflag = 0;
                  obj.isSupSend = 0;
                  obj.wReadFlag = 0;
                  obj.gooAccMxId = 0;
                  obj.id = this.difInfo[j].id;
                  obj.isSupSend = this.difInfo[j].isSupSend;
                  obj.goods_accountattachmentDetail = [];
                  obj.goods_accountattachmentDetail.push(this.difInfo[j]);
                  this.storageSelRows[i].accountmxmsg.push(obj);
                }
              }
            }
          }
          obj.companyCode = this.selCompanyCode.companyCode;
          obj.creator = this.$global.user.employeeName;
          obj.creatorId = this.$global.user.id;
          obj.type = this.selAccountCode;
          obj.flag = 1;
          obj.zbflag = 1;
          obj.gooAccNo = this.phyCode;
          obj.id = 0;
          obj.modifyer = this.$global.user.employeeName;
          obj.modifyerId = this.$global.user.id;
          obj.remark = this.remark;
          obj.supplierCode = this.supplierInfo[0].supplierCode; //supplier[0].supplierCode;
          obj.recordDetail = this.storageSelRows;
          this.btnDis = true;
          _Api
            .postPhysicalAccount(obj)
            .then(function (response) {
              var data = response.data;
              if (data.code == "1") {
                Msg.showSuccessMsg("保存成功");
                that.cancel();
                that.btnDis = false;
              } else {
                Msg.showErrorMsg(data.info);
                that.btnDis = false;
              }
            })
            .catch((err) => {
              Msg.showErrorMsg(err.data.message);
              that.btnDis = false;
            });
        } else if (this.pageLayOut == "edit") {
          var clickValue = this.setClickValue;
          for (let i = this.storageSelRows.length - 1; i >= 0; i--) {
            if (this.storageSelRows[i].id > 0) this.storageSelRows.splice(i, 1);
          }
          for (let i = this.storageSelRows.length - 1; i >= 0; i--) {
            if (this.storageSelRows.isTotal) this.storageSelRows.splice(i, 1);
          }
          this.btnDis = true;
          if (this.difInfo.length > 0) {
            for (let i = 0; i < this.storageSelRows.length; i++) {
              this.storageSelRows[i].accountmxmsg = [];
              for (let j = 0; j < this.difInfo.length; j++) {
                let obj = {};
                if (
                  this.difInfo[j].instockNo ==
                    this.storageSelRows[i].instockNo &&
                  this.difInfo[j].instockMxNo ==
                    this.storageSelRows[i].instockMxNo
                ) {
                  obj.content = this.difInfo[j].content;
                  obj.creator = this.$global.user.employeeName;
                  obj.creatorId = this.$global.user.id;
                  obj.modifyer = this.$global.user.employeeName;
                  obj.modifyerId = this.$global.user.id;
                  obj.sender = this.difInfo[j].sender;
                  obj.senderId = this.difInfo[j].senderId;
                  obj.greadflag = 0;
                  obj.isSupSend = this.difInfo[j].isSupSend;
                  obj.wReadFlag = 0;
                  obj.gooAccMxId = 0;
                  obj.id = this.difInfo[j].id;
                  obj.goods_accountattachmentDetail = [];
                  obj.goods_accountattachmentDetail.push(this.difInfo[j]);
                  this.storageSelRows[i].accountmxmsg.push(obj);
                }
              }
            }
          }
          obj.companyCode = this.selCompanyCode.companyCode;
          obj.creator = this.$global.user.employeeName;
          obj.creatorId = this.$global.user.id;
          obj.type = this.selAccountCode;
          obj.flag = 1;
          obj.zbflag = 1;
          obj.gooAccNo = this.phyCode;
          obj.id = clickValue.id;
          obj.modifyer = this.$global.user.employeeName;
          obj.modifyerId = this.$global.user.id;
          obj.remark = this.remark;
          obj.supplierCode = this.supplierInfo[0].supplierCode;
          obj.recordDetail = this.storageSelRows;
          _Api
            .postPhysicalAccount(obj)
            .then(function (response) {
              var data = response.data;
              if (data.code == "1") {
                Msg.showSuccessMsg("保存成功");
                that.cancel();
              } else {
                Msg.showErrorMsg(data.info);
              }
              that.btnDis = false;
            })
            .catch((err) => {
              Msg.showErrorMsg(err.data.message);
              that.btnDis = false;
            });
        }
      } else {
        this.accountSavePhyData();
      }
    },
    accountSavePhyData() {
      //非供应商用户保存数据
      for (let i = this.storageSelRows.length - 1; i >= 0; i--) {
        if (this.storageSelRows[i].isTotal) this.storageSelRows.splice(i, 1);
      }
      //          for(let i = this.storageSelRows.length - 1;i >= 0;i--){
      //				if(this.storageSelRows[i].id > 0)
      //					this.storageSelRows.splice(i,1);
      //			}
      var obj = {};
      var that = this;
      if (this.difInfo.length > 0) {
        for (let i = 0; i < this.storageSelRows.length; i++) {
          this.storageSelRows[i].accountmxmsg = [];
          for (let j = 0; j < this.difInfo.length; j++) {
            let obj = {};
            if (!this.difInfo[j].isExist) {
              if (
                this.difInfo[j].instockNo == this.storageSelRows[i].instockNo &&
                this.difInfo[j].instockMxNo ==
                  this.storageSelRows[i].instockMxNo
              ) {
                obj.content = this.difInfo[j].content;
                obj.creator = this.$global.user.employeeName;
                obj.creatorId = this.$global.user.id;
                obj.modifyer = this.$global.user.employeeName;
                obj.modifyerId = this.$global.user.id;
                obj.greadflag = 0;
                obj.isSupSend = this.difInfo[j].isSupSend;
                obj.wReadFlag = 0;
                obj.gooAccMxId = 0; //this.mxId
                obj.id = this.difInfo[j].id;
                obj.goods_accountattachmentDetail = [];
                obj.goods_accountattachmentDetail.push(this.difInfo[j]);
                this.storageSelRows[i].accountmxmsg.push(obj);
              }
            }
          }
        }
      }
      obj.companyCode = this.selCompanyCode.companyCode;
      obj.creator = this.$global.user.employeeName;
      obj.creatorId = this.$global.user.id;
      obj.type = this.selAccountCode;
      obj.flag = 1;
      obj.zbflag = 1;
      obj.gooAccNo = this.phyCode;
      obj.id = this.setClickValue.id;
      obj.modifyer = this.$global.user.employeeName;
      obj.modifyerId = this.$global.user.id;
      obj.remark = this.remark;
      obj.subFlag = 1;
      obj.recordDetail = this.storageSelRows;
      this.btnDis = true;
      _Api
        .putPhysicalAccount(obj)
        .then(function (response) {
          let data = response.data;
          if (data.code == "1") {
            Msg.showSuccessMsg("保存成功");
            that.cancel();
          } else {
            Msg.showErrorMsg(data.info);
          }
          that.btnDis = false;
        })
        .catch((err) => {
          Msg.showErrorMsg(err.data.message);
          that.btnDis = false;
        });
    },
    submitPhyData() {
      if (this.orderSelRows.length <= 0 || this.storageSelRows.length <= 0) {
        Msg.showPopMsg("提示：请选择需要保存的数据！");
        return;
      }
      for (let i = this.storageSelRows.length - 1; i >= 0; i--) {
        if (this.storageSelRows[i].isTotal) this.storageSelRows.splice(i, 1);
      }
      var that = this;
      var obj = {};
      if (this.pageLayOut == "add") {
        if (this.difInfo.length > 0) {
          for (let i = 0; i < this.storageSelRows.length; i++) {
            this.storageSelRows[i].accountmxmsg = [];
            for (let j = 0; j < this.difInfo.length; j++) {
              let obj = {};
              if (this.difInfo[j].id <= 0) {
                if (
                  this.difInfo[j].instockNo ==
                    this.storageSelRows[i].instockNo &&
                  this.difInfo[j].instockMxNo ==
                    this.storageSelRows[i].instockMxNo
                ) {
                  obj.content = this.difInfo[j].content;
                  obj.creator = this.$global.user.employeeName;
                  obj.creatorId = this.$global.user.id;
                  obj.modifyer = this.$global.user.employeeName;
                  obj.modifyerId = this.$global.user.id;
                  obj.sender = this.difInfo[j].sender;
                  obj.senderId = this.difInfo[j].senderId;
                  obj.greadflag = 0;
                  obj.isSupSend = 0;
                  obj.wReadFlag = 0;
                  obj.gooAccMxId = 0;
                  obj.id = this.difInfo[j].id;
                  obj.isSupSend = this.difInfo[j].isSupSend;
                  obj.goods_accountattachmentDetail = [];
                  obj.goods_accountattachmentDetail.push(this.difInfo[j]);
                  this.storageSelRows[i].accountmxmsg.push(obj);
                }
              }
            }
          }
        }
        obj.companyCode = this.selCompanyCode.companyCode;
        obj.creator = this.$global.user.employeeName;
        obj.creatorId = this.$global.user.id;
        obj.type = this.selAccountCode;
        obj.summitterId = this.$global.user.id;
        obj.submitter = this.$global.user.employeeName;
        obj.flag = 2; //提交
        obj.zbflag = 1;
        obj.gooAccNo = this.phyCode;
        obj.id = 0;
        obj.modifyer = this.$global.user.employeeName;
        obj.modifyerId = this.$global.user.id;
        obj.remark = this.remark;
        obj.supplierCode = this.supplierInfo[0].supplierCode; //supplier[0].supplierCode;
        obj.recordDetail = this.storageSelRows;
        this.btnDis = true;
        _Api
          .postPhysicalAccount(obj)
          .then(function (response) {
            var data = response.data;
            if (data.code == "1") {
              Msg.showSuccessMsg("提交成功");
              that.cancel();
            } else {
              Msg.showErrorMsg(data.info);
            }
            that.btnDis = false;
          })
          .catch((err) => {
            that.btnDis = false;
            Msg.showErrorMsg(err.data.message);
          });
      } else if (this.pageLayOut == "edit") {
        var clickValue = this.setClickValue;
        for (let i = this.storageSelRows.length - 1; i >= 0; i--) {
          if (this.storageSelRows[i].id > 0) this.storageSelRows.splice(i, 1);
        }
        if (this.difInfo.length > 0) {
          for (let i = 0; i < this.storageSelRows.length; i++) {
            this.storageSelRows[i].accountmxmsg = [];
            for (let j = 0; j < this.difInfo.length; j++) {
              let obj = {};
              if (
                this.difInfo[j].instockNo == this.storageSelRows[i].instockNo &&
                this.difInfo[j].instockMxNo ==
                  this.storageSelRows[i].instockMxNo
              ) {
                obj.content = this.difInfo[j].content;
                obj.creator = this.$global.user.employeeName;
                obj.creatorId = this.$global.user.id;
                obj.type = this.selAccountCode;
                obj.modifyer = this.$global.user.employeeName;
                obj.modifyerId = this.$global.user.id;
                obj.sender = this.difInfo[j].sender;
                obj.senderId = this.difInfo[j].senderId;
                obj.greadflag = 0;
                obj.isSupSend = this.difInfo[j].isSupSend;
                obj.wReadFlag = 0;
                obj.gooAccMxId = 0;
                obj.id = this.difInfo[j].id;
                obj.goods_accountattachmentDetail = [];
                obj.goods_accountattachmentDetail.push(this.difInfo[j]);
                this.storageSelRows[i].accountmxmsg.push(obj);
              }
            }
          }
        }
        obj.companyCode = this.selCompanyCode.companyCode;
        obj.creator = this.$global.user.employeeName;
        obj.creatorId = this.$global.user.id;
        obj.summitterId = this.$global.user.id;
        obj.submitter = this.$global.user.employeeName;
        obj.type = this.selAccountCode;
        obj.flag = 2; //提交
        obj.zbflag = 1;
        obj.gooAccNo = this.phyCode;
        obj.id = clickValue.id;
        obj.modifyer = this.$global.user.employeeName;
        obj.modifyerId = this.$global.user.id;
        obj.remark = this.remark;
        obj.supplierCode = this.supplierInfo[0].supplierCode; //supplier[0].supplierCode;
        obj.recordDetail = this.storageSelRows;
        this.btnDis = true;
        _Api
          .postPhysicalAccount(obj)
          .then(function (response) {
            var data = response.data;
            if (data.code == "1") {
              Msg.showSuccessMsg("提交成功");
              that.cancel();
            } else {
              Msg.showErrorMsg(data.info);
            }
            that.btnDis = false;
          })
          .catch((err) => {
            that.btnDis = false;
            Msg.showErrorMsg(err.data.message);
          });
      }
    },
    phyStorageSelected(row) {
      var that = this;
      var instockNo = row.data.instockNo; //入库单号
      var rowIndex = row.rowIndex;
      var purOrdNo = row.data.purOrdNo; //订单号
      var purOrdMxNo = row.data.purOrdMxNo; //订单行号
      //判断差异字段是否属于勾选状态
      if (row.colDef.field == "adjust") {
        if (row.node.selected == false) {
          this.$refs.phyStorageAgGrid.gridOptions.api.forEachNode(function (
            node
          ) {
            if (node.rowIndex == rowIndex) node.setSelected(true);
          });
        } else if (row.node.selected == true) {
          this.$refs.phyStorageAgGrid.gridOptions.api.forEachNode(function (
            node
          ) {
            if (node.rowIndex == rowIndex) node.setSelected(false);
          });
        }
        return;
      }
      if (row.node.selected == true) {
        //当前节点勾选状态
        if (this.selConfiguration == "single") {
          //页面配置单选
          this.$refs.phyOrderAgGrid.gridOptions.api.forEachNode(function (
            node
          ) {
            if (
              node.data.purOrdNo == row.node.data.purOrdNo &&
              node.data.purOrdMxNo == row.node.data.purOrdMxNo
            )
              node.setSelected(true);
          });
        } else if (this.selConfiguration == "multiple") {
          //页面配置多选
          this.$refs.phyStorageAgGrid.gridOptions.api.forEachNode(function (
            node
          ) {
            if (node.data.instockNo == instockNo) node.setSelected(true);
            that.$refs.phyOrderAgGrid.gridOptions.api.forEachNode(function (
              node1
            ) {
              if (
                node1.data.purOrdNo == node.data.purOrdNo &&
                node1.data.purOrdMxNo == node.data.purOrdMxNo &&
                node.selected == true
              )
                node1.setSelected(true);
            });
          });
        }
      } else if (row.node.selected == false) {
        //当前节点取消勾选状态
        var sum = 0; //当前节点信息在当前表单里面的总数
        if (this.selConfiguration == "single") {
          //页面配置单选
          this.$refs.phyStorageAgGrid.gridOptions.api.forEachNode(function (
            node
          ) {
            if (
              node.data.purOrdNo == purOrdNo &&
              node.data.purOrdMxNo == purOrdMxNo &&
              node.selected == true
            ) {
              sum++;
            }
          });
          if (sum >= 1) {
            this.$refs.phyOrderAgGrid.gridOptions.api.forEachNode(function (
              node
            ) {
              if (
                node.data.purOrdNo == purOrdNo &&
                node.data.purOrdMxNo == purOrdMxNo
              )
                node.setSelected(true);
            });
          } else {
            this.$refs.phyOrderAgGrid.gridOptions.api.forEachNode(function (
              node
            ) {
              if (
                node.data.purOrdNo == purOrdNo &&
                node.data.purOrdMxNo == purOrdMxNo
              )
                node.setSelected(false);
            });
          }
        } else if (this.selConfiguration == "multiple") {
          //页面配置多选
          this.$refs.phyStorageAgGrid.gridOptions.api.forEachNode(function (
            node
          ) {
            if (node.data.instockNo == instockNo) node.setSelected(false);
          });
          let selRows = JSON.parse(
            JSON.stringify(
              this.$refs.phyStorageAgGrid.gridOptions.api.getSelectedRows()
            )
          );
          this.$refs.phyOrderAgGrid.gridOptions.api.forEachNode(function (
            node
          ) {
            node.setSelected(false);
            for (let i = 0; i < selRows.length; i++) {
              if (
                node.data.purOrdNo == selRows[i].purOrdNo &&
                node.data.purOrdMxNo == selRows[i].purOrdMxNo
              ) {
                node.setSelected(true);
              }
            }
          });
        }
      }
    },
    getPhysicalNo() {
      var that = this;
      _Api
        .getPhysicalNo()
        .then(function (response) {
          // var data = response.data;
          //              if (data.code == "1") {
          //                  if (data.total > 0) {
          //                      that.phyCode = data.rows.GoodAccountNO;
          //                  }
          //              }
          if (response.status == "200") that.phyCode = response.data;
        })
        .catch((err) => {
          Msg.showErrorMsg(err.data.message);
        });
    },
    cancel: function () {
      //console.log("取消");
      if (this.pageLayOut == "add") {
        let list = {
          cName: "实物对账列表",
          name: "goodsAccountBill",
          completed: true,
          refresh: true,
        };
        this.removeTab();
        this.addTab(list);
        // console.log("关闭")
      } else {
        this.$emit("cancelComponents", true);
      }
    },
    sendDifInfo() {
      if (!this.difDetailInfo.orgName && !this.difRuleForm.difDetail) {
        Msg.showPopMsg("请上传相关附件/输入差异说明！");
        return;
      }
      var that = this;
      if (!this.getClickDetailInfo.id) {
        this.sendBtn = true;
        _Api
          .getServerTime()
          .then(function (response) {
            let data = response.data;
            if (data.code == "1") {
              let dt = new Date(data.timestamp);
              let obj = {};
              that.$refs["diffUpload"].clearFileList();
              obj.createDate = dt.Format("yyyy-MM-dd HH:mm:ss");
              obj.attachmentName = that.difDetailInfo.orgName;
              obj.content = that.difRuleForm.difDetail;
              obj.phyCode = that.phyCode;
              obj.instockNo = that.clickRowData.instockNo;
              obj.instockMxNo = that.clickRowData.instockMxNo;
              obj.visible = true;
              obj.url = that.difDetailInfo.fileName;
              if (that.$global.user.userTypeId == "4") {
                obj.creator = that.$global.user.employeeName;
                obj.creatorId = that.$global.user.id;
                obj.isSupSend = 1;
                obj.sender = that.supplierInfo[0].supplierName;
                obj.senderId = that.supplierInfo[0].id;
              } else {
                obj.creator = that.$global.user.employeeName;
                obj.creatorId = that.$global.user.id;
                obj.isSupSend = 2;
                obj.sender = that.comName;
                obj.senderId = that.selCompanyCode.companyCode;
              }
              obj.size = that.difDetailInfo.fileSize;
              obj.id = 0;
              obj.gooAccMxMsgId = 0;
              that.difInfo.push(obj); //unshift
              that.$refs["difRuleForm"].resetFields();
              // that.$refs.upload.clearFiles();
              that.difDetailInfo = {};
            }
            that.sendBtn = false;
          })
          .catch((err) => {
            Msg.showErrorMsg(err.data.message);
            that.sendBtn = false;
          });
      } else {
        var obj = {
          content: this.difRuleForm.difDetail,
          creator: this.$global.user.employeeName,
          creatorId: this.$global.user.id,
          gReadFlag: 0,
          lTblGoodsAccountattachment: [
            {
              attachmentName: this.difDetailInfo.orgName,
              creator: this.$global.user.employeeName,
              creatorId: this.$global.user.id,
              size: this.difDetailInfo.fileSize,
              url: this.difDetailInfo.fileName,
            },
          ],
        };
        if (this.$global.user.userTypeId == "4") {
          obj.isSupSend = 1;
          obj.creator = this.$global.user.employeeName;
          obj.creatorId = this.$global.user.id;
          obj.sender = this.supplierInfo[0].supplierName;
          obj.senderId = this.supplierInfo[0].id;
        } else {
          obj.isSupSend = 2;
          obj.creator = this.$global.user.employeeName;
          obj.creatorId = this.$global.user.id;
          obj.sender = this.comName;
          obj.senderId = this.selCompanyCode.companyCode;
        }
        if (this.pageLayOut == "edit") {
          if (this.getClickDetailInfo.id != "") {
            obj.gooAccMxId = this.getClickDetailInfo.id;
          } else {
            obj.gooAccMxId = 0;
          }
        } else {
          obj.gooAccMxId = 0;
        }
        this.sendBtn = true;
        _Api
          .addDiffDetailInfo(obj)
          .then(function (response) {
            let data = response.data;
            if (data.code == "1") {
              Msg.showSuccessMsg("保存成功");
              that.$refs["diffUpload"].clearFileList();
              // let userName = this.$global.user.employeeName;
              let obj = {};
              obj.attachmentName = that.difDetailInfo.orgName;
              obj.content = that.difRuleForm.difDetail;
              obj.phyCode = that.phyCode;
              obj.instockNo = that.clickRowData.instockNo;
              obj.instockMxNo = that.clickRowData.instockMxNo;
              obj.visible = true;
              obj.url = that.difDetailInfo.fileName;
              if (that.$global.user.userTypeId == "4") {
                obj.creator = that.$global.user.employeeName;
                obj.creatorId = that.$global.user.id;
                obj.sender = that.supplierInfo[0].supplierName;
                obj.senderId = that.supplierInfo[0].id;
                obj.isSupSend = 1;
              } else {
                obj.creator = that.$global.user.employeeName;
                obj.creatorId = that.$global.user.id;
                obj.isSupSend = 2;
                obj.sender = that.comName;
                obj.senderId = that.selCompanyCode.companyCode;
              }
              obj.size = that.difDetailInfo.fileSize;
              obj.gooAccMxMsgId = 0;
              obj.id = 0;
              obj.gooAccMxMsgId = 0;
              obj.isExist = true; //标识
              let date2 = new Date(data.timestamp);
              obj.createDate = date2.Format("yyyy-MM-dd HH:mm:ss");
              that.difInfo.push(obj); //unshift
              that.$refs["difRuleForm"].resetFields();
              // that.$refs.upload.clearFiles();
              that.difDetailInfo = [];
              that.sendBtn = false;
            } else {
              Msg.showErrorMsg(data.info);
              that.sendBtn = false;
            }
          })
          .catch((err) => {
            Msg.showErrorMsg(err.data.message);
            that.sendBtn = false;
          });
      }
    },
    showDifDialog(params) {
      this.sendShow = true;
      console.log("擦会议说明", this.difInfo);
      if (!params.id) {
        //新增未保存数据
        if (this.difInfo.length > 0) {
          for (let i = 0; i < this.difInfo.length; i++) {
            if (
              this.difInfo[i].instockNo == params.instockNo &&
              this.difInfo[i].instockMxNo == params.instockMxNo &&
              this.difInfo[i].phyCode == this.phyCode
            )
              this.difInfo[i].visible = true;
            else {
              this.difInfo[i].visible = false;
            }
          }
        } else {
          // if(this.$global.user.userTypeId == "4")
          //     this.supplierSend ++;
          // else
          //     this.accountSend ++;
        }
        this.mxId = 0;
        // if(this.$global.user.userTypeId != "4")
        //     this.sendShow = false;
      } else {
        this.mxId = params.id;
        //已经存在ID
        this.getClickDetailInfo = params;
        var that = this;
        let obj = {
          id: params.id,
        };
        for (let i = this.difInfo.length - 1; i >= 0; i--) {
          if (this.difInfo[i].id != 0) this.difInfo.splice(i, 1);
        }
        _Api
          .getGoodsAccountMxmsg(obj)
          .then(function (response) {
            let data = response.data;
            if (data.code == "1") {
              for (
                let i = 0;
                i < data.rows.ltbl_goods_accountmxmsg.length;
                i++
              ) {
                var obj = {};
                obj.content = data.rows.ltbl_goods_accountmxmsg[i].content;
                obj.instockNo = params.instockNo;
                obj.instockMxNo = params.instockMxNo;
                obj.createDate =
                  data.rows.ltbl_goods_accountmxmsg[i].createDate;
                obj.isSupSend = data.rows.ltbl_goods_accountmxmsg[i].isSupSend;
                obj.sender = data.rows.ltbl_goods_accountmxmsg[i].sender;
                obj.senderId = data.rows.ltbl_goods_accountmxmsg[i].senderId;
                for (
                  let j = 0;
                  j <
                  data.rows.ltbl_goods_accountmxmsg[i]
                    .lTblGoodsAccountattachment.length;
                  j++
                ) {
                  obj.creator =
                    data.rows.ltbl_goods_accountmxmsg[
                      i
                    ].lTblGoodsAccountattachment[j].creator;
                  obj.attachmentName =
                    data.rows.ltbl_goods_accountmxmsg[
                      i
                    ].lTblGoodsAccountattachment[j].attachmentName;
                  obj.url =
                    data.rows.ltbl_goods_accountmxmsg[
                      i
                    ].lTblGoodsAccountattachment[j].url;
                }
                if (
                  obj.instockNo == params.instockNo &&
                  obj.instockMxNo == params.instockMxNo
                )
                  obj.visible = true;
                else obj.visible = false;
                obj.id = data.rows.ltbl_goods_accountmxmsg[i].id;
                obj.gooAccMxMsgId = data.rows.ltbl_goods_accountmxmsg[i].id;
                obj.phyCode = that.phyCode;
                obj.isExist = true;
                that.difInfo.unshift(obj);
              }
              //去除重复行
              for (let i = 0; i < that.difInfo.length; i++) {
                for (let j = 0; j < that.difInfo.length; j++) {
                  if (i != j) {
                    if (
                      that.difInfo[i].instockNo == that.difInfo[j].instockNo &&
                      that.difInfo[i].instockMxNo == that.difInfo[j].instockMxNo
                    ) {
                      if (that.difInfo[j].id == 0) {
                        that.difInfo.splice(j, 1);
                      }
                    }
                  }
                }
              }
              for (let i = 0; i < that.difInfo.length; i++) {
                if (
                  that.difInfo[i].instockNo == params.instockNo &&
                  that.difInfo[i].instockMxNo == params.instockMxNo
                )
                  that.difInfo[i].visible = true;
                else that.difInfo[i].visible = false;
              }
              if (that.setClickValue.billState == 1) {
                if (params.confirmFlag == "1") {
                  that.sendShow = false;
                } else {
                  that.sendShow = true;
                }
              } else if (that.setClickValue.billState == 2) {
                if (that.$global.user.userTypeId == "4") {
                  that.sendShow = false;
                } else {
                  if (params.confirmFlag == "1") {
                    that.sendShow = false;
                  } else {
                    let count = 0;
                    for (let i = 0; i < that.difInfo.length; i++) {
                      if (
                        that.difInfo[i].instockMxNo == params.instockMxNo &&
                        that.difInfo[i].instockNo == params.instockNo
                      )
                        count++;
                    }
                    // if(count > 0)
                    //     that.sendShow = true;
                    // else
                    //     that.sendShow = false;
                  }
                }
              } else {
                that.sendShow = false;
              }
              //                      if(that.difInfo.length > 0)
              //                      	that.difInfo.sort(that.compareDown("id"));
            } else {
              Msg.showErrorMsg(data.info);
              that.difInfo = [];
            }
          })
          .catch((err) => {
            Msg.showErrorMsg(err.data.message);
            that.difInfo = [];
          });
      }
      this.difInfoDialogVisible = true;
      this.clickRowData = params;
      this.upload_url = this.$uploadUrl;
      //this.upload_url="http://172.16.100.45:49231/srm/upload/file";
    },
    getFileInfo(msg) {
      var userName = this.$global.user.employeeName;
      var obj = {};
      obj.userName = userName;
      obj.file = msg.orgName;
      obj.remark = this.difRuleForm.difDetail;
      this.difInfo.push(obj);
      //console.log(this.difInfo);
      this.$refs["difRuleForm"].resetFields();
    },
    getUploadFile(msg) {
      this.file = msg;
    },
    handlePreview(file) {
      //console.log(file);
    },
    handleRemove(file, fileList) {
      if (this.$refs.upload.uploadFiles.length <= 0) {
        this.difDetailInfo = {};
      }
      this.filename = "";
    },
    beforeRemove(file, fileList) {
      // return this.$confirm(`确定移除 ${ file.name }？`).catch(()=>{});
    },
    change(file) {
      // this.upload_url="http://172.16.100.45:49231/srm/upload/file";
      this.upload_url = this.$uploadUrl;
      this.filename = file.name;
    },
    uploadSuccess(response, file, fileList) {
      if (response.code == 1) {
        Msg.showSuccessMsg("上传成功");
        //              console.log(response.rows[0]);
        //保存文件信息
        this.difDetailInfo = response.rows[0];
      } else {
        Msg.showErrorMsg("操作失败！");
        this.$refs.upload.clearFiles();
      }
    },
    beforeAvatarUpload(file) {
      var fileType = file.name.substring(file.name.lastIndexOf(".") + 1);
      if (fileType) {
        var fy = fileType.toLowerCase();
        if (
          fy != "txt" &&
          fy != "pdf" &&
          fy != "doc" &&
          fy != "docx" &&
          fy != "xls" &&
          fy != "xlsx"
        ) {
          this.$message({
            message: "上传文件类型只支持.txt/.pdf/.doc/.docx/.xls/.xlsx ！",
            type: "warning",
          });
          return false;
        }
        const size = file.size / 1024 / 1024 < 20;
        if (!size) {
          this.$message({
            message: "上传模板大小不能超过 20MB!",
            type: "warning",
          });
          return false;
        }
      }
    },
    downLoadFile(item) {
      var group = "";
      if (item.url.indexOf("SRM") > -1) {
        group = "SRM";
      } else if (item.url.indexOf("SIGN") > -1) {
        group = "SIGN";
      } else if (item.url.indexOf("TEST") > -1) {
        group = "TEST";
      } else if (item.url.indexOf("MES") > -1) {
        group = "MES";
      }
      var obj = {
        viewPath: item.url,
        groupName: group,
        fileName: "",
      };
      downLoadFileFunc(obj, item.attachmentName);
      //   var that = this;
      //   _Api.templateDownload(obj).then(function (response) {
      //     var data = response.data;
      //     // if (data.code == "1") {
      //     //   if (data.total > 0) {
      //         //                      console.log(data.rows[0].fileName);
      //         console.log(data.code)
      //         that.downLoad(data, item.attachmentName);//data.rows[0].filename
      //     //   }
      //     // }
      //   })
      //   .catch(err => {
      //       Msg.showErrorMsg(err.data.message);
      //   } )
    },
    downLoad(data, fileName) {
      var eleLink = document.createElement("a");
      eleLink.style.display = "none";
      eleLink.setAttribute("href", url); //文件下载地址
      eleLink.setAttribute("download", filename); //download属性只能在同域实现
      // 触发点击
      document.body.appendChild(eleLink);
      eleLink.click();
      // 然后移除
      document.body.removeChild(eleLink);
    },
    confirmPhyData() {
      var that = this;
      this.$prompt("审批意见", "消息提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        customClass: "promitBox",
        inputType: "textarea",
        inputValue: "核对无误,可以开票",
        distinguishCancelAndClose: true,
      })
        .then(({ value }) => {
          for (let a in that.storageSelRows) {
            if (that.storageSelRows[a].isMsExist >= 1) {
              if (that.storageSelRows[a].confirmFlag == 0) {
                Msg.showPopMsg(
                  "请先确认入库单号为：" +
                    that.storageSelRows[a].instockNo +
                    " 的差异再进行提交操作！"
                );
                return;
              }
            }
          }
          var obj = {};
          if (this.difInfo.length > 0) {
            for (let i = 0; i < that.storageSelRows.length; i++) {
              that.storageSelRows[i].accountmxmsg = [];
              for (let j = 0; j < that.difInfo.length; j++) {
                let obj = {};
                if (!this.difInfo[j].isExist) {
                  if (
                    that.difInfo[j].instockNo ==
                      that.storageSelRows[i].instockNo &&
                    that.difInfo[j].instockMxNo ==
                      that.storageSelRows[i].instockMxNo
                  ) {
                    obj.content = that.difInfo[j].content;
                    obj.creator = this.$global.user.employeeName;
                    obj.creatorId = this.$global.user.id;
                    obj.modifyer = this.$global.user.employeeName;
                    obj.modifyerId = this.$global.user.id;
                    obj.greadflag = 0;
                    obj.isSupSend = 0;
                    obj.wReadFlag = 0;
                    obj.gooAccMxId = 0;
                    obj.id = that.difInfo[j].id;
                    obj.goods_accountattachmentDetail = [];
                    obj.goods_accountattachmentDetail.push(that.difInfo[j]);
                    that.storageSelRows[i].accountmxmsg.push(obj);
                  }
                }
              }
            }
          }
          obj.companyCode = that.selCompanyCode.companyCode;
          obj.creator = this.$global.user.employeeName;
          obj.creatorId = this.$global.user.id;
          obj.type = this.selAccountCode;
          obj.flag = 1;
          obj.zbflag = 1;
          obj.gooAccNo = that.phyCode;
          obj.id = that.setClickValue.id;
          obj.modifyer = this.$global.user.employeeName;
          obj.modifyerId = this.$global.user.id;
          obj.confirmerId = this.$global.user.id;
          obj.confirmer = this.$global.user.employeeName;
          obj.remark = that.remark;
          obj.subFlag = 3;
          obj.supplierId = that.setClickValue.supplierId;
          obj.companyId = that.setClickValue.companyId;
          obj.recordDetail = that.storageSelRows;
          obj.signOption = value;
          that.btnDis = true;
          _Api
            .putPhysicalAccount(obj)
            .then(function (response) {
              let data = response.data;
              if (data.code == "1") {
                Msg.showSuccessMsg("操作成功");
                that.cancel();
              } else {
                Msg.showErrorMsg(data.info);
              }
              that.btnDis = false;
            })
            .catch((err) => {
              Msg.showErrorMsg(err.data.message);
              that.btnDis = false;
            });
        })
        .catch(() => {});
    },
    rollbackPhyData() {
      var that = this;
      this.$prompt("审批意见", "消息提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        customClass: "promitBox",
        inputType: "textarea",
        inputValidator: (val) => {
          if (!val) {
            return "审批意见不能为空";
          }
        },
        distinguishCancelAndClose: true,
      })
        .then(({ value }) => {
          var obj = {};
          for (let i = this.storageSelRows.length - 1; i >= 0; i--) {
            if (this.storageSelRows[i].isTotal)
              this.storageSelRows.splice(i, 1);
          }
          if (this.difInfo.length > 0) {
            for (let i = 0; i < that.storageSelRows.length; i++) {
              that.storageSelRows[i].accountmxmsg = [];
              for (let j = 0; j < that.difInfo.length; j++) {
                let obj = {};
                if (!this.difInfo[j].isExist) {
                  if (
                    that.difInfo[j].instockNo ==
                      that.storageSelRows[i].instockNo &&
                    that.difInfo[j].instockMxNo ==
                      that.storageSelRows[i].instockMxNo
                  ) {
                    obj.content = that.difInfo[j].content;
                    obj.creator = this.$global.user.employeeName;
                    obj.creatorId = this.$global.user.id;
                    obj.modifyer = this.$global.user.employeeName;
                    obj.modifyerId = this.$global.user.id;
                    obj.greadflag = 0;
                    obj.isSupSend = 0;
                    obj.wReadFlag = 0;
                    obj.gooAccMxId = 0;
                    obj.id = that.difInfo[j].id;
                    obj.goods_accountattachmentDetail = [];
                    obj.goods_accountattachmentDetail.push(that.difInfo[j]);
                    that.storageSelRows[i].accountmxmsg.push(obj);
                  }
                }
              }
            }
          }
          obj.companyCode = that.selCompanyCode.companyCode;
          obj.creator = this.$global.user.employeeName;
          obj.creatorId = this.$global.user.id;
          obj.type = that.selAccountCode;
          obj.flag = 1;
          obj.zbflag = 1;
          obj.gooAccNo = that.phyCode;
          obj.id = that.setClickValue.id;
          obj.modifyer = this.$global.user.employeeName;
          obj.modifyerId = this.$global.user.id;
          obj.remark = that.remark;
          obj.subFlag = 2;
          obj.supplierId = that.setClickValue.supplierId;
          obj.companyId = that.setClickValue.companyId;
          obj.summitterId = that.setClickValue.summitterId;
          obj.recordDetail = that.storageSelRows;
          obj.signOption = value;
          that.btnDis = true;
          console.log(obj);
          _Api
            .putPhysicalAccount(obj)
            .then(function (response) {
              let data = response.data;
              if (data.code == "1") {
                Msg.showSuccessMsg("操作成功");
                that.cancel();
              } else {
                Msg.showErrorMsg(data.info);
              }
              that.btnDis = false;
            })
            .catch((err) => {
              Msg.showErrorMsg(err.data.message);
              that.btnDis = false;
            });
        })
        .catch(() => {});
    },
    getGoodsDetails(phyCode) {
      //根据实物对账单号获取 明细信息
      var obj = {
        gooAccNo: phyCode,
      };
      var that = this;
      this.loading = true;
      this.btnDis = true;
      _Api
        .getGoodsDetails(obj)
        .then(function (response) {
          let data = response.data;
          that.btnDis = false;
          if (data.code == "1") {
            if (data.rows.m_StorageTotal.length > 0) {
              that.orderSelRows = data.rows.m_StorageTotal;
              that.$refs.phyOrderAgGrid.gridOptions.api.setRowData(
                that.orderSelRows
              );
              // let allColumnIds = [];
              // that.$refs.phyOrderAgGrid.gridOptions.columnApi.getAllColumns().forEach(function (column) {
              //   allColumnIds.push(column.colId);
              // });
              //jjc20181220 注释
              //that.$refs.phyOrderAgGrid.gridOptions.columnApi.autoSizeColumns(allColumnIds);
            }
            if (data.rows.m_StorageDetail.length > 0) {
              that.storageSelRows = data.rows.m_StorageDetail;
              if (that.pageLayOut == "edit") {
                for (let a = that.rows.length - 1; a >= 0; a--) {
                  that.storageSelRows.push(that.rows[a]);
                  that.rows.splice(a, 1);
                }
              }
              //添加合计信息
              that.billTotalMoney = 0;
              that.billTotalCount = 0;
              that.billTotalAdjust = 0;
              that.selBillTotalMoney = 0;
              that.selBillTotalAdjust = 0;
              for (let i = 0; i < that.storageSelRows.length; i++) {
                that.billTotalMoney = that.accAdd(
                  that.storageSelRows[i].realMoney,
                  that.billTotalMoney
                );
                that.billTotalCount = that.accAdd(
                  that.storageSelRows[i].amount,
                  that.billTotalCount
                );
                that.billTotalAdjust = that.accAdd(
                  that.storageSelRows[i].adjustMoney,
                  that.billTotalAdjust
                );

                that.selBillTotalMoney = that.accAdd(
                  that.storageSelRows[i].realMoney,
                  that.selBillTotalMoney
                );
                that.selBillTotalAdjust = that.accAdd(
                  that.storageSelRows[i].adjustMoney,
                  that.selBillTotalAdjust
                );
              }
              that.billTotalMoney = that.accAdd(
                that.billTotalMoney,
                that.billTotalAdjust
              );

              that.billTotalMoney = that.billTotalMoney
                .toString()
                .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
              that.billTotalCount = that.billTotalCount
                .toString()
                .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
              that.selBillTotalMoney = that.selBillTotalMoney
                .toString()
                .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");

              that.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(
                that.createData(1, "Bottom")
              );
              //合计行
              //                      let obj = {};
              //	                    obj.amount = 0;
              //			            obj.realMoney = 0;
              //                      for(let i = 0; i < that.storageSelRows.length;i++){
              //			            	obj.matName = "合计";
              //			            	obj.amount = that.accAdd(obj.amount,that.storageSelRows[i].amount);
              //			            	obj.realMoney = that.accAdd(obj.realMoney,that.storageSelRows[i].realMoney);
              //			            	obj.isTotal = 1;
              //			            }
              //			            that.storageSelRows.push(obj);

              //                   let allColumnIds = [];
              // that.$refs.phyStorageAgGrid.gridOptions.columnApi.getAllColumns().forEach(function(column) {
              // 	allColumnIds.push(column.colId);
              // });
              // that.$refs.phyStorageAgGrid.gridOptions.columnApi.autoSizeColumns(allColumnIds);
              that.$refs.phyStorageAgGrid.gridOptions.api.setRowData(
                that.storageSelRows
              );
              // that.$refs.phyStorageAgGrid.gridOptions.api.sizeColumnsToFit();
            }
            //勾选入库数量赋值
            that.$refs.phyOrderAgGrid.gridOptions.api.forEachNode(function (
              node
            ) {
              let rowIndex = that.$refs.phyOrderAgGrid.gridOptions.api.getRowNode(
                node.rowIndex
              );
              let sum = 0;
              let sumMoney = 0;
              for (let i = 0; i < that.storageSelRows.length; i++) {
                if (
                  that.storageSelRows[i].purOrdNo == node.data.purOrdNo &&
                  that.storageSelRows[i].purOrdMxNo == node.data.purOrdMxNo
                ) {
                  // sum += that.storageSelRows[i].amount;
                  sum = that.accAdd(sum, that.storageSelRows[i].amount);
                  // sumMoney += that.storageSelRows[i].realMoney;
                  sumMoney = that.accAdd(
                    sumMoney,
                    that.storageSelRows[i].realMoney
                  );
                }
              }
              rowIndex.setDataValue("selAmount", sum);
              rowIndex.setDataValue("selMoney", sumMoney);
            });
            //       that.$refs.phyStorageAgGrid.gridOptions.api.refreshCells({
            // 	columns:['confirmFlag']
            // })
            that.loading = false;
          } else {
            Msg.showErrorMsg(data.info);
            that.orderSelRows = [];
            that.$refs.phyOrderAgGrid.gridOptions.api.setRowData(
              that.orderSelRows
            );
            that.storageSelRows = [];
            that.$refs.phyStorageAgGrid.gridOptions.api.setRowData(
              that.storageSelRows
            );
            that.loading = false;
          }
        })
        .catch((err) => {
          Msg.showErrorMsg(err.data.message);
          that.orderSelRows = [];
          //that.$refs.phyOrderAgGrid.gridOptions.api.setRowData(that.orderSelRows);
          that.storageSelRows = [];
          //that.$refs.phyStorageAgGrid.gridOptions.api.setRowData(that.storageSelRows);
          that.loading = false;
        });
    },
    difDialogClose(done) {
      var that = this;
      this.getClickDetailInfo = {};
      if (this.pageLayOut == "add") {
        that.$refs["difRuleForm"].resetFields();
        // that.$refs.upload.clearFiles();
      } else if (this.pageLayOut == "edit") {
        if (this.$global.user.userTypeId == "4") {
          if (this.setClickValue.billState == "1") {
            // && this.$global.user.userTypeId == "4"
            if (that.$refs.difRuleForm) that.$refs["difRuleForm"].resetFields();
            // if (that.$refs.upload)
            //   that.$refs.upload.clearFiles();
          }
        } else {
          if (this.setClickValue.billstate == "2") {
            that.$refs["difRuleForm"].resetFields();
            // that.$refs.upload.clearFiles();
          }
        }
      }

      done();
    },
    adjustMoney() {
      var that = this;
      this.$confirm("是否确认调整金额？", "消息提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        distinguishCancelAndClose: true,
      })
        .then(() => {
          let lTblAdjustbill = [];
          for (let i = 0; i < that.storageSelRows.length; i++) {
            let obj = {};
            obj.purOrdNo = that.storageSelRows[i].purOrdNo;
            obj.purOrdMxNo = that.storageSelRows[i].purOrdMxNo;
            obj.instockMxNo = that.storageSelRows[i].instockMxNo;
            obj.instockNo = that.storageSelRows[i].instockNo;
            obj.amount = that.storageSelRows[i].amount;
            lTblAdjustbill.push(obj);
          }
          let obj2 = {
            lTblAdjustbill: lTblAdjustbill,
          };
          _Api.phyAdjustMoney(obj2).then(function (response) {
            let data = response.data;
            if (data.code == "1") {
              if (data.total > 0) {
                that.$refs.phyStorageAgGrid.gridOptions.api.forEachNode(
                  function (node) {
                    let rowIndex = that.$refs.phyStorageAgGrid.gridOptions.api.getRowNode(
                      node.rowIndex
                    );
                    for (let i = 0; i < data.rows.length; i++) {
                      if (data.rows[i]) {
                        if (
                          data.rows[i].purOrdNo == node.data.purOrdNo &&
                          data.rows[i].purOrdMxNo == node.data.purOrdMxNo
                        )
                          rowIndex.setDataValue(
                            "adjustMoney",
                            data.rows[i].diffMoney
                          );
                      }
                    }
                  }
                );
              }
            }
          });
        })
        .catch(() => {});
    },
    confirm(params) {
      var obj = {};
      var that = this;
      this.$confirm("是否确认该数据？", "消息提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        distinguishCancelAndClose: true,
      })
        .then(() => {
          waterfall([
            function confirmDetail(callback) {
              obj.id = params.data.id;
              obj.modifyerId = that.$global.user.id;
              obj.modifyer = that.$global.user.employeeName;
              obj.confirmFlag = 1;
              _Api
                .phyDetailConfirm(obj)
                .then(function (response) {
                  let data = response.data;
                  if (data.code == "1") {
                    that.$message({
                      message: "操作成功",
                      type: "success",
                    });
                    // for(let i in that.storageSelRows){
                    // 	if(!that.storageSelRows[i].id)
                    // 		that.rows.push(that.storageSelRows[i]);
                    // }
                    let rowIndex = that.$refs.phyStorageAgGrid.gridOptions.api.getRowNode(
                      params.rowIndex
                    );
                    rowIndex.setDataValue("confirmFlag", 1);
                    callback(null);
                  } else {
                    Msg.showErrorMsg(data.info);
                  }
                })
                .catch((err) => {
                  Msg.showErrorMsg(err.data.message);
                });
            },
            // function getGoodsDetails(callback){
            //     that.getGoodsDetails(that.setClickValue.gooAccNo);
            // }
          ]);
        })
        .catch(() => {});
    },
    accAdd(arg1, arg2) {
      var r1, r2, m, c;
      try {
        r1 = arg1.toString().split(".")[1].length;
      } catch (e) {
        r1 = 0;
      }
      try {
        r2 = arg2.toString().split(".")[1].length;
      } catch (e) {
        r2 = 0;
      }
      c = Math.abs(r1 - r2);
      m = Math.pow(10, Math.max(r1, r2));
      if (c > 0) {
        var cm = Math.pow(10, c);
        if (r1 > r2) {
          arg1 = Number(arg1.toString().replace(".", ""));
          arg2 = Number(arg2.toString().replace(".", "")) * cm;
        } else {
          arg1 = Number(arg1.toString().replace(".", "")) * cm;
          arg2 = Number(arg2.toString().replace(".", ""));
        }
      } else {
        arg1 = Number(arg1.toString().replace(".", ""));
        arg2 = Number(arg2.toString().replace(".", ""));
      }
      return (arg1 + arg2) / m;
    },
    deleteDetails(params) {
      var that = this;
      var sumId = 0;
      if (params.id) {
        that.$refs.phyStorageAgGrid.gridOptions.api.forEachNode(function (
          node
        ) {
          if (node.data.id) sumId++;
        });
        if (sumId == 1) {
          Msg.showPopMsg("至少保留1条已保存的数据！");
          return;
        }
      }

      this.$confirm("是否确认删除该数据？", "消息提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        distinguishCancelAndClose: true,
      })
        .then(() => {
          if (params.id) {
            let obj = {
              id: params.id,
            };
            _Api
              .deleteGoodsDetails(obj)
              .then(function (response) {
                let data = response.data;
                if (data.code == "1") {
                  let sum1 = 0;
                  that.$refs.phyStorageAgGrid.gridOptions.api.forEachNode(
                    function (node) {
                      if (
                        node.data.purOrdMxNo == params.purOrdMxNo &&
                        node.data.purOrdNo == params.purOrdNo
                      ) {
                        sum1++;
                      }
                    }
                  );
                  //判断当前数据是否属于唯一数据
                  if (sum1 > 1) {
                    //删除指定行
                    let arr1 = [];
                    arr1.push(params);
                    that.$refs.phyStorageAgGrid.gridOptions.api.updateRowData({
                      remove: arr1,
                    });
                    //计算
                    let sumAmount = 0;
                    let sumMoney = 0;
                    that.$refs.phyStorageAgGrid.gridOptions.api.forEachNode(
                      function (node) {
                        if (
                          node.data.purOrdNo == params.purOrdNo &&
                          node.data.purOrdMxNo == params.purOrdMxNo
                        ) {
                          sumAmount += node.data.amount;
                          sumMoney += node.data.realMoney;
                        }
                      }
                    );
                    //赋值
                    that.$refs.phyOrderAgGrid.gridOptions.api.forEachNode(
                      function (node) {
                        let rowIndex = that.$refs.phyOrderAgGrid.gridOptions.api.getRowNode(
                          node.rowIndex
                        );
                        if (
                          node.data.purOrdNo == params.purOrdNo &&
                          node.data.purOrdMxNo == params.purOrdMxNo
                        ) {
                          rowIndex.setDataValue("selAmount", sumAmount);
                          rowIndex.setDataValue("selMoney", sumMoney);
                        }
                      }
                    );
                    //在数组里面删除指定对象
                    for (let i = that.storageSelRows.length - 1; i >= 0; i--) {
                      if (
                        that.storageSelRows[i].instockNo == params.instockNo &&
                        that.storageSelRows[i].instockMxNo == params.instockMxNo
                      )
                        that.storageSelRows.splice(i, 1);
                    }
                    for (let i = that.orderSelRows.length - 1; i >= 0; i--) {
                      if (
                        that.orderSelRows[i].purOrdNo == params.purOrdNo &&
                        params.purOrdMxNo == that.orderSelRows[i].purOrdMxNo
                      )
                        that.orderSelRows.splice(i, 1);
                    }
                    //重新加入数组
                    that.$refs.phyOrderAgGrid.gridOptions.api.forEachNode(
                      function (node) {
                        if (
                          node.data.purOrdNo == params.purOrdNo &&
                          node.data.purOrdMxNo == params.purOrdMxNo
                        ) {
                          that.orderSelRows.push(node.data);
                          //                          console.log(that.orderSelRows);
                        }
                      }
                    );
                  } else {
                    let arr1 = [];
                    that.$refs.phyOrderAgGrid.gridOptions.api.forEachNode(
                      function (node) {
                        if (
                          node.data.purOrdNo == params.purOrdNo &&
                          node.data.purOrdMxNo == params.purOrdMxNo
                        ) {
                          arr1.push(node.data);
                        }
                      }
                    );
                    let arr2 = [];
                    arr2.push(params);
                    that.$refs.phyOrderAgGrid.gridOptions.api.updateRowData({
                      remove: arr1,
                    });
                    that.$refs.phyOrderAgGrid.gridOptions.api.hideOverlay();
                    that.$refs.phyStorageAgGrid.gridOptions.api.updateRowData({
                      remove: arr2,
                    });
                    that.$refs.phyStorageAgGrid.gridOptions.api.hideOverlay();
                    for (let i = that.storageSelRows.length - 1; i >= 0; i--) {
                      if (
                        that.storageSelRows[i].instockMxNo ==
                          params.instockMxNo &&
                        params.instockNo == that.storageSelRows[i].instockNo
                      )
                        that.storageSelRows.splice(i, 1);
                    }
                    for (let i = that.orderSelRows.length - 1; i >= 0; i--) {
                      if (
                        that.orderSelRows[i].purOrdNo == params.purOrdNo &&
                        that.orderSelRows[i].purOrdMxNo == params.purOrdMxNo
                      )
                        that.orderSelRows.splice(i, 1);
                    }
                  }

                  //重新合计
                  //			                for(let i = that.storageSelRows.length - 1;i >= 0;i--){
                  //			                	if(that.storageSelRows[i].isTotal)
                  //			                		that.storageSelRows.splice(i,1);
                  //			                }
                  //			                if(that.storageSelRows.length > 0){
                  //			                	let obj = {};//合计行
                  //					            obj.amount = 0;
                  //					            obj.realMoney = 0;
                  //					            for(let i = 0; i < that.storageSelRows.length;i++){
                  //					            	obj.matName = "合计";
                  //					            	obj.amount = that.accAdd(obj.amount,that.storageSelRows[i].amount);
                  //					            	obj.realMoney = that.accAdd(obj.realMoney,that.storageSelRows[i].realMoney);
                  //					            	obj.isTotal = 1;
                  //					            }
                  //			//		            that.storageSelRows.push(obj);
                  //								that.billTotalMoney = obj.realMoney;
                  //					            that.billTotalCount = obj.amount;
                  //								that.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(that.createData(1,"Bottom"));
                  //					            that.$refs.phyStorageAgGrid.gridOptions.api.setRowData(that.storageSelRows);
                  //			                }else{
                  //			                	that.$refs.phyStorageAgGrid.gridOptions.api.setRowData(that.storageSelRows);
                  //			                	that.billTotalMoney = 0;
                  //			                	that.billTotalCount = 0;
                  //			                	that.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(that.createData(1,"Bottom"));
                  //			                }
                  //重新合计
                  for (let i = that.storageSelRows.length - 1; i >= 0; i--) {
                    if (that.storageSelRows[i].isTotal)
                      that.storageSelRows.splice(i, 1);
                  }
                  if (that.storageSelRows.length > 0) {
                    let obj = {}; //合计行
                    obj.amount = 0;
                    obj.realMoney = 0;
                    obj.adjustMoney = 0;
                    for (let i = 0; i < that.storageSelRows.length; i++) {
                      obj.matName = "合计";
                      obj.amount = that.accAdd(
                        obj.amount,
                        that.storageSelRows[i].amount
                      );
                      obj.realMoney = that.accAdd(
                        obj.realMoney,
                        that.storageSelRows[i].realMoney
                      );
                      obj.adjustMoney = that.accAdd(
                        obj.adjustMoney,
                        that.storageSelRows[i].adjustMoney
                      );
                      obj.isTotal = 1;
                    }
                    that.billTotalMoney = obj.realMoney + obj.adjustMoney;
                    that.billTotalCount = obj.amount;
                    that.selBillTotalCount = obj.amount;
                    that.selBillTotalMoney = obj.realMoney;
                    that.selBillTotalAdjust = obj.adjustMoney;
                    that.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(
                      that.createSelData(1, "Bottom")
                    );
                    that.$refs.phyStorageAgGrid.gridOptions.api.setRowData(
                      that.storageSelRows
                    );
                  } else {
                    that.$refs.phyStorageAgGrid.gridOptions.api.setRowData(
                      that.storageSelRows
                    );
                    that.billTotalMoney = 0;
                    that.billTotalCount = 0;
                    that.selBillTotalCount = 0;
                    that.selBillTotalMoney = 0;
                    that.selBillTotalAdjust = 0;
                    that.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(
                      that.createSelData(1, "Bottom")
                    );
                  }
                } else {
                  Msg.showErrorMsg(data.info);
                }
              })
              .catch((err) => {
                Msg.showErrorMsg(err.data.message);
              });
          } else {
            let sum1 = 0;
            //删除指定附件 by lxh 2019-02-20
            for (let i = that.difInfo.length - 1; i >= 0; i--) {
              if (
                that.difInfo[i].instockMxNo == params.instockMxNo &&
                that.difInfo[i].instockNo == params.instockNo &&
                that.difInfo[i].phyCode == that.phyCode
              ) {
                that.difInfo.splice(i, 1);
              }
            }
            that.$refs.phyStorageAgGrid.gridOptions.api.forEachNode(function (
              node
            ) {
              if (
                node.data.purOrdMxNo == params.purOrdMxNo &&
                node.data.purOrdNo == params.purOrdNo
              ) {
                sum1++;
              }
            });
            //判断当前数据是否属于唯一数据
            if (sum1 > 1) {
              //删除指定行
              let arr1 = [];
              arr1.push(params);
              that.$refs.phyStorageAgGrid.gridOptions.api.updateRowData({
                remove: arr1,
              });
              //计算
              let sumAmount = 0;
              let sumMoney = 0;
              that.$refs.phyStorageAgGrid.gridOptions.api.forEachNode(function (
                node
              ) {
                if (
                  node.data.purOrdNo == params.purOrdNo &&
                  node.data.purOrdMxNo == params.purOrdMxNo
                ) {
                  sumAmount += node.data.amount;
                  sumMoney += node.data.realMoney;
                }
              });
              //赋值
              that.$refs.phyOrderAgGrid.gridOptions.api.forEachNode(function (
                node
              ) {
                let rowIndex = that.$refs.phyOrderAgGrid.gridOptions.api.getRowNode(
                  node.rowIndex
                );
                if (
                  node.data.purOrdNo == params.purOrdNo &&
                  node.data.purOrdMxNo == params.purOrdMxNo
                ) {
                  rowIndex.setDataValue("selAmount", sumAmount);
                  rowIndex.setDataValue("selMoney", sumMoney);
                }
              });
              //在数组里面删除指定对象
              for (let i = that.storageSelRows.length - 1; i >= 0; i--) {
                if (
                  that.storageSelRows[i].instockNo == params.instockNo &&
                  that.storageSelRows[i].instockMxNo == params.instockMxNo
                )
                  that.storageSelRows.splice(i, 1);
              }
              for (let i = that.orderSelRows.length - 1; i >= 0; i--) {
                if (
                  that.orderSelRows[i].purOrdNo == params.purOrdNo &&
                  params.purOrdMxNo == that.orderSelRows[i].purOrdMxNo
                )
                  that.orderSelRows.splice(i, 1);
              }
              //重新加入数组
              that.$refs.phyOrderAgGrid.gridOptions.api.forEachNode(function (
                node
              ) {
                if (
                  node.data.purOrdNo == params.purOrdNo &&
                  node.data.purOrdMxNo == params.purOrdMxNo
                ) {
                  that.orderSelRows.push(node.data);
                  //                          console.log(that.orderSelRows);
                }
              });
              //重新计算
              for (let i = that.storageSelRows.length - 1; i >= 0; i--) {
                if (that.storageSelRows[i].isTotal)
                  that.storageSelRows.splice(i, 1);
              }
              if (that.storageSelRows.length > 0) {
                let obj = {}; //合计行
                obj.amount = 0;
                obj.realMoney = 0;
                obj.adjustMoney = 0;
                for (let i = 0; i < that.storageSelRows.length; i++) {
                  obj.matName = "合计";
                  obj.amount = that.accAdd(
                    obj.amount,
                    that.storageSelRows[i].amount
                  );
                  obj.realMoney = that.accAdd(
                    obj.realMoney,
                    that.storageSelRows[i].realMoney
                  );
                  obj.adjustMoney = that.accAdd(
                    obj.adjustMoney,
                    that.storageSelRows[i].adjustMoney
                  );
                  obj.isTotal = 1;
                }
                //                  that.storageSelRows.push(obj);
                that.billTotalMoney = obj.realMoney + obj.adjustMoney;
                that.billTotalCount = obj.amount;
                that.selBillTotalCount = obj.amount;
                that.selBillTotalMoney = obj.realMoney;
                that.selBillTotalAdjust = obj.adjustMoney;
                that.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(
                  that.createSelData(1, "Bottom")
                );
                that.$refs.phyStorageAgGrid.gridOptions.api.setRowData(
                  that.storageSelRows
                );
              } else {
                that.$refs.phyStorageAgGrid.gridOptions.api.setRowData(
                  that.storageSelRows
                );
                that.billTotalMoney = 0;
                that.billTotalCount = 0;
                that.selBillTotalCount = 0;
                that.selBillTotalMoney = 0;
                that.selBillTotalAdjust = 0;
                that.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(
                  that.createSelData(1, "Bottom")
                );
              }
            } else {
              let arr1 = [];
              that.$refs.phyOrderAgGrid.gridOptions.api.forEachNode(function (
                node
              ) {
                if (
                  node.data.purOrdNo == params.purOrdNo &&
                  node.data.purOrdMxNo == params.purOrdMxNo
                ) {
                  arr1.push(node.data);
                }
              });
              let arr2 = [];
              arr2.push(params);
              that.$refs.phyOrderAgGrid.gridOptions.api.updateRowData({
                remove: arr1,
              });
              that.$refs.phyStorageAgGrid.gridOptions.api.updateRowData({
                remove: arr2,
              });
              for (let i = that.storageSelRows.length - 1; i >= 0; i--) {
                if (
                  that.storageSelRows[i].instockMxNo == params.instockMxNo &&
                  params.instockNo == that.storageSelRows[i].instockNo
                )
                  that.storageSelRows.splice(i, 1);
              }
              for (let i = that.orderSelRows.length - 1; i >= 0; i--) {
                if (
                  that.orderSelRows[i].purOrdNo == params.purOrdNo &&
                  that.orderSelRows[i].purOrdMxNo == params.purOrdMxNo
                )
                  that.orderSelRows.splice(i, 1);
              }
            }

            //重新合计
            for (let i = that.storageSelRows.length - 1; i >= 0; i--) {
              if (that.storageSelRows[i].isTotal)
                that.storageSelRows.splice(i, 1);
            }
            if (that.storageSelRows.length > 0) {
              let obj = {}; //合计行
              obj.amount = 0;
              obj.realMoney = 0;
              obj.adjustMoney = 0;
              for (let i = 0; i < that.storageSelRows.length; i++) {
                obj.matName = "合计";
                obj.amount = that.accAdd(
                  obj.amount,
                  that.storageSelRows[i].amount
                );
                obj.realMoney = that.accAdd(
                  obj.realMoney,
                  that.storageSelRows[i].realMoney
                );
                obj.adjustMoney = that.accAdd(
                  obj.adjustMoney,
                  that.storageSelRows[i].adjustMoney
                );
                obj.isTotal = 1;
              }
              //		            that.storageSelRows.push(obj);
              that.billTotalMoney = obj.realMoney + obj.adjustMoney;
              that.billTotalCount = obj.amount;
              that.selBillTotalCount = obj.amount;
              that.selBillTotalMoney = obj.realMoney;
              that.selBillTotalAdjust = obj.adjustMoney;
              that.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(
                that.createSelData(1, "Bottom")
              );
              that.$refs.phyStorageAgGrid.gridOptions.api.setRowData(
                that.storageSelRows
              );
            } else {
              that.$refs.phyStorageAgGrid.gridOptions.api.setRowData(
                that.storageSelRows
              );
              that.billTotalMoney = 0;
              that.billTotalCount = 0;
              that.selBillTotalCount = 0;
              that.selBillTotalMoney = 0;
              that.selBillTotalAdjust = 0;
              that.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(
                that.createSelData(1, "Bottom")
              );
            }
          }
        })
        .catch(() => {});
    },
    phyOrderRowClicked(row) {
      var that = this;
      var hardCodeFilter = {
        purOrdNo: { type: "equals", filter: row.data.purOrdNo },
        purOrdMxNo: { type: "equals", filter: row.data.purOrdMxNo },
      };
      this.$refs.phyOrderAgGrid.gridOptions.api.deselectAll();
      this.$refs.phyStorageAgGrid.gridOptions.api.setFilterModel(
        hardCodeFilter
      );
      this.$refs.phyStorageAgGrid.gridOptions.api.onFilterChanged();
      this.selBillTotalCount = 0;
      this.selBillTotalMoney = 0;
      this.selBillTotalAdjust = 0;
      this.$refs.phyStorageAgGrid.gridOptions.api.forEachNodeAfterFilter(
        function (node) {
          that.selBillTotalCount = that.accAdd(
            node.data.amount,
            that.selBillTotalCount
          );
          that.selBillTotalMoney = that.accAdd(
            node.data.realMoney,
            that.selBillTotalMoney
          );
          that.selBillTotalAdjust = that.accAdd(
            node.data.adjustMoney,
            that.selBillTotalAdjust
          );
          that.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(
            that.createSelData(1, "Bottom")
          );
        }
      );
      //          let arr = [];
      //          for(let i = 0;i<this.storageSelRows.length;i++){
      //              if(this.storageSelRows[i].purOrdNo == row.data.purOrdNo && this.storageSelRows[i].purOrdMxNo == row.data.purOrdMxNo){
      //                  arr.push(this.storageSelRows[i]);
      //              }
      //          }
      //          for(let i = this.storageSelRows.length - 1;i >= 0;i--){
      //          	if(this.storageSelRows[i].isTotal)
      //          		this.storageSelRows.splice(i,1);
      //          }
      //
      //          let obj = {};//合计行
      //          obj.amount = 0;
      //          obj.realMoney = 0;
      //          obj.adjustMoney = 0;
      //          for(let i = 0; i < arr.length;i++){
      //          	obj.matName = "合计";
      //          	obj.amount = that.accAdd(obj.amount,arr[i].amount);
      //          	obj.realMoney = that.accAdd(obj.realMoney,arr[i].realMoney);
      //          	obj.adjustMoney = that.accAdd(obj.adjustMoney,arr[i].adjustMoney);
      //          	obj.isTotal = 1;
      //          }
      ////          arr.push(obj);
      //			this.selBillTotalCount = obj.amount;
      //  		this.selBillTotalMoney = obj.realMoney;
      //  		this.selBillTotalAdjust = obj.adjustMoney;
      //
      //          this.selBillTotalCount = this.selBillTotalCount.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
      //          this.selBillTotalMoney = this.selBillTotalMoney.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
      //          this.selBillTotalAdjust = this.selBillTotalAdjust.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
      //
      //          this.$refs.phyStorageAgGrid.gridOptions.api.setRowData(arr);
      //          this.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(this.createSelData(1,"Bottom"));
    },
    phyOrderRowSelected(row) {
      var that = this;
      var rows = this.$refs.phyOrderAgGrid.gridOptions.api.getSelectedRows();
      if (rows.length > 0) {
        this.$refs.phyOrderAgGrid.gridOptions.api.setFilterModel(null);
        this.$refs.phyOrderAgGrid.gridOptions.api.onFilterChanged();
        this.$refs.phyStorageAgGrid.gridOptions.api.setFilterModel(null);
        this.$refs.phyStorageAgGrid.gridOptions.api.onFilterChanged();
        this.selBillTotalCount = 0;
        this.selBillTotalMoney = 0;
        this.selBillTotalAdjust = 0;
        this.$refs.phyStorageAgGrid.gridOptions.api.forEachNodeAfterFilter(
          function (node) {
            that.selBillTotalCount = that.accAdd(
              node.data.amount,
              that.selBillTotalCount
            );
            that.selBillTotalMoney = that.accAdd(
              node.data.realMoney,
              that.selBillTotalMoney
            );
            that.selBillTotalAdjust = that.accAdd(
              node.data.adjustMoney,
              that.selBillTotalAdjust
            );
            that.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(
              that.createSelData(1, "Bottom")
            );
          }
        );
      }
      //      	if(row.node.selected){
      //              var count = 0;
      //              for(let a in this.selectedRows){
      //                  if(this.selectedRows[a].purOrdNo == row.data.purOrdNo && this.selectedRows[a].purOrdMxNo == row.data.purOrdMxNo)
      //                      count ++ ;
      //              }
      //              if(count <= 0){
      //                  for(let i = 0;i<this.storageSelRows.length;i++){
      //                      if(row.data.purOrdNo == this.storageSelRows[i].purOrdNo && row.data.purOrdMxNo == this.storageSelRows[i].purOrdMxNo){
      //                          this.selectedRows.push(this.storageSelRows[i]);
      //                      }
      //                  }
      //              }
      //      		// for(let i = 0;i<this.storageSelRows.length;i++){
      //      		// 	if(row.data.purOrdNo == this.storageSelRows[i].purOrdNo && row.data.purOrdMxNo == this.storageSelRows[i].purOrdMxNo){
      //      		// 		this.selectedRows.push(this.storageSelRows[i]);
      //      		// 	}
      //      		// }
      //      		//删除多余行
      //	            for(let i = this.selectedRows.length - 1;i >= 0;i--){
      //	            	if(this.selectedRows[i].isTotal)
      //	            		this.selectedRows.splice(i,1);
      //	            }
      //	            let obj = {};
      //	            obj.amount = 0;
      //	            obj.realMoney = 0;
      //	            obj.adjustMoney = 0;
      //      		for(let i = 0 ;i<this.selectedRows.length;i++){
      //      			obj.matName = "合计";
      //					obj.amount = this.accAdd(obj.amount,this.selectedRows[i].amount);
      //					obj.realMoney = this.accAdd(obj.realMoney,this.selectedRows[i].realMoney);
      //					obj.adjustMoney = this.accAdd(obj.adjustMoney,this.selectedRows[i].adjustMoney);
      //      			obj.isTotal = 1;
      //      		}
      //      		this.selBillTotalCount = obj.amount;
      //      		this.selBillTotalMoney = obj.realMoney;
      //      		this.selBillTotalAdjust = obj.adjustMoney;
      //
      //              this.selBillTotalCount = this.selBillTotalCount.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
      //              this.selBillTotalMoney = this.selBillTotalMoney.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
      //              this.selBillTotalAdjust = this.selBillTotalAdjust.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
      //
      ////      		this.selectedRows.push(obj);
      //      		this.$refs.phyStorageAgGrid.gridOptions.api.setRowData(this.selectedRows);
      //      		this.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(this.createSelData(1,"Bottom"));
      //      	}else{
      //      		for(var i = this.selectedRows.length - 1;i >= 0 ;i--){
      //      			if(!row.node.selected){
      //      				if(this.selectedRows[i].purOrdNo == row.data.purOrdNo && this.selectedRows[i].purOrdMxNo == row.data.purOrdMxNo)
      //      					this.selectedRows.splice(i,1);
      //      			}
      //      		}
      //      		for(var i = this.selectedRows.length - 1;i >= 0 ;i--){
      //      			if(this.selectedRows[i].isTotal)
      //      				this.selectedRows.splice(i,1);
      //      		}
      //      		//统计剩余行
      //      		if(this.selectedRows.length > 0){
      //      			let obj = {};
      //	        		obj.amount = 0;
      //	        		obj.realMoney = 0;
      //                  obj.adjustMoney = 0;
      //	        		for(let i = 0;i<this.selectedRows.length;i++){
      //	        			obj.matName = "合计";
      //	        			obj.amount = this.accAdd(obj.amount,this.selectedRows[i].amount);
      //						obj.realMoney = this.accAdd(obj.realMoney,this.selectedRows[i].realMoney);
      //                      obj.adjustMoney = this.accAdd(obj.adjustMoney,this.selectedRows[i].adjustMoney);
      //	        			obj.isTotal = 1;
      //	        		}
      ////	        		this.selectedRows.push(obj);
      //					this.selBillTotalCount = obj.amount;
      //      			this.selBillTotalMoney = obj.realMoney;
      //                  this.selBillTotalAdjust = obj.adjustMoney;
      //					this.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(this.createSelData(1,"Bottom"));
      //	        		this.$refs.phyStorageAgGrid.gridOptions.api.setRowData(this.selectedRows);
      //      		}else{
      //                  var focusedCell = this.$refs.phyOrderAgGrid.gridOptions.api.getFocusedCell();
      //                  if(!focusedCell){
      //                      var displayedRow = this.$refs.phyOrderAgGrid.gridOptions.api.getDisplayedRowAtIndex(0);
      //                      if(displayedRow){
      //                          for(let j in this.storageSelRows){
      //                              if(this.storageSelRows[j].purOrdNo == displayedRow.data.purOrdNo && this.storageSelRows[j].purOrdMxNo == displayedRow.data.purOrdMxNo)
      //                                  this.selectedRows.push(this.storageSelRows[j]);
      //                          }
      //                      }
      //                      let obj = {};
      //                      obj.amount = 0;
      //                      obj.realMoney = 0;
      //                      obj.adjustMoney = 0;
      //                      for(let k in this.selectedRows){
      //                          obj.amount = this.accAdd(this.selectedRows[k].amount,obj.amount);
      //                          obj.realMoney = this.accAdd(this.selectedRows[k].realMoney,obj.realMoney);
      //                          obj.adjustMoney = this.accAdd(this.selectedRows[k].adjustMoney,obj.adjustMoney);
      //                      }
      //                      this.selBillTotalCount = obj.amount;
      //                      this.selBillTotalMoney = obj.realMoney;
      //                      this.selBillTotalAdjust = obj.adjustMoney;
      //
      //                      this.selBillTotalCount = this.selBillTotalCount.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
      //                      this.selBillTotalMoney = this.selBillTotalMoney.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
      //                      this.selBillTotalAdjust = this.selBillTotalAdjust.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
      //
      //                      this.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(this.createSelData(1,"Bottom"));
      //                      this.$refs.phyStorageAgGrid.gridOptions.api.setRowData(this.selectedRows);
      //                  }else{
      //                      var displayedRow = this.$refs.phyOrderAgGrid.gridOptions.api.getDisplayedRowAtIndex(focusedCell.rowIndex);
      //                      if(displayedRow)
      //                      {
      //                          for(let j in this.storageSelRows){
      //                              if(this.storageSelRows[j].purOrdNo == displayedRow.data.purOrdNo && this.storageSelRows[j].purOrdMxNo == displayedRow.data.purOrdMxNo)
      //                                  this.selectedRows.push(this.storageSelRows[j]);
      //                          }
      //                          let obj = {};
      //                          obj.amount = 0;
      //                          obj.realMoney = 0;
      //                          obj.adjustMoney = 0;
      //                          for(let k in this.selectedRows){
      //                              obj.amount = this.accAdd(this.selectedRows[k].amount,obj.amount);
      //                              obj.realMoney = this.accAdd(this.selectedRows[k].realMoney,obj.realMoney);
      //                              obj.adjustMoney = this.accAdd(this.selectedRows[k].adjustMoney,obj.adjustMoney);
      //                          }
      //                          this.selBillTotalCount = obj.amount;
      //                          this.selBillTotalMoney = obj.realMoney;
      //                          this.selBillTotalAdjust = obj.adjustMoney;
      //
      //                          this.selBillTotalCount = this.selBillTotalCount.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
      //                          this.selBillTotalMoney = this.selBillTotalMoney.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
      //                          this.selBillTotalAdjust = this.selBillTotalAdjust.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
      //
      //                          this.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(this.createSelData(1,"Bottom"));
      //                          this.$refs.phyStorageAgGrid.gridOptions.api.setRowData(this.selectedRows);
      //                      }
      //                  }
      //              }
      //      	}
    },
    storageInfoSel(params) {
      if (params.node.selected) {
        this.storageInfoOptions.api.forEachNode(function (node) {
          if (node.data.instockNo == params.data.instockNo)
            node.setSelected(true);
        });
      } else {
        this.storageInfoOptions.api.forEachNode(function (node) {
          if (node.data.instockNo == params.data.instockNo)
            node.setSelected(false);
        });
      }
    },
    addStandByRows() {
      var that = this;
      this.tempSelectedRows = [];
      this.storageInfoOptions.api.forEachNode(function (node) {
        if (node.selected) {
          that.tempSelectedRows.push(node.data);
          that.storageSelRows.push(node.data);
        } else {
          for (let i = that.storageSelRows.length - 1; i >= 0; i--) {
            if (
              that.storageSelRows[i].instockNo == node.data.instockNo &&
              that.storageSelRows[i].instockMxNo == node.data.instockMxNo
            )
              that.storageSelRows.splice(i, 1);
          }
        }
      });
      //去除重复行
      for (let j = 0; j < this.storageSelRows.length; j++) {
        for (let k = 0; k < this.storageSelRows.length; k++) {
          if (j != k) {
            if (
              this.storageSelRows[j].instockNo ==
                this.storageSelRows[k].instockNo &&
              this.storageSelRows[k].instockMxNo ==
                this.storageSelRows[j].instockMxNo
            )
              this.storageSelRows.splice(k, 1);
          }
        }
      }
      this.standbyInfoOptions.api.setRowData(this.storageSelRows);
    },
    saveStandbyData() {
      if (this.standbyInfoOptions.api.rowModel.rowsToDisplay.length == 0) {
        Msg.showPopMsg("待选明细为空，请添加入库明细！");
        return;
      }
      for (let i = this.storageSelRows.length - 1; i >= 0; i--) {
        if (this.storageSelRows[i].isTotal) this.storageSelRows.splice(i, 1);
        delete this.storageSelRows[i].selAmount;
        delete this.storageSelRows[i].selMoney;
      }
      if (this.storageSelRows.length > 0) {
        let obj = {}; //合计行
        obj.amount = 0;
        obj.realMoney = 0;
        obj.adjustMoney = 0;
        for (let i = 0; i < this.storageSelRows.length; i++) {
          if (!this.storageSelRows[i].adjustMoney)
            this.storageSelRows[i].adjustMoney = 0;
          obj.matName = "合计";
          obj.amount = this.accAdd(obj.amount, this.storageSelRows[i].amount);
          obj.realMoney = this.accAdd(
            obj.realMoney,
            this.storageSelRows[i].realMoney
          );
          obj.adjustMoney = this.accAdd(
            obj.adjustMoney,
            this.storageSelRows[i].adjustMoney
          );
          obj.isTotal = 1;
        }
        this.billTotalMoney = this.accAdd(obj.realMoney, obj.adjustMoney);
        //	        	this.storageSelRows.push(obj);
        this.billTotalCount = obj.amount;
        this.selBillTotalMoney = obj.realMoney; //billTotalMoney
        this.selBillTotalAdjust = obj.adjustMoney; //billTotalAdjust

        this.billTotalMoney = this.billTotalMoney
          .toString()
          .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
        this.billTotalCount = this.billTotalCount
          .toString()
          .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
        this.selBillTotalMoney = this.selBillTotalMoney
          .toString()
          .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
        this.selBillTotalAdjust = this.selBillTotalAdjust
          .toString()
          .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
      } else {
        this.billTotalCount = 0;
        this.selBillTotalMoney = 0;
        this.selBillTotalAdjust = 0;
      }

      this.$refs.phyStorageAgGrid.gridOptions.api.setRowData(
        this.storageSelRows
      );
      //      	let allColumnIds = [];
      // this.$refs.phyStorageAgGrid.gridOptions.columnApi.getAllColumns().forEach(function(column) {
      // 	allColumnIds.push(column.colId);
      // });
      // this.$refs.phyStorageAgGrid.gridOptions.columnApi.autoSizeColumns(allColumnIds);
      //   this.$refs.phyStorageAgGrid.gridOptions.api.sizeColumnsToFit();
      //合并行
      this.orderSelRows = [];
      for (let i = 0; i < this.storageSelRows.length; i++) {
        this.orderSelRows.push(this.storageSelRows[i]);
      }
      for (let i = 0; i < this.orderSelRows.length; i++) {
        for (let j = 0; j < this.orderSelRows.length; j++) {
          if (i != j) {
            if (
              this.orderSelRows[i].purOrdNo == this.orderSelRows[j].purOrdNo &&
              this.orderSelRows[i].purOrdMxNo == this.orderSelRows[j].purOrdMxNo
            ) {
              this.orderSelRows[i].selAmount = this.accAdd(
                this.orderSelRows[i].amount,
                this.orderSelRows[j].amount
              );
              this.orderSelRows[i].selMoney = this.accAdd(
                this.orderSelRows[i].realMoney,
                this.orderSelRows[j].realMoney
              );
              this.orderSelRows.splice(j, 1);
              j = 0;
            }
          }
        }
      }
      for (let i = 0; i < this.orderSelRows.length; i++) {
        if (!this.orderSelRows[i].selAmount)
          this.orderSelRows[i].selAmount = this.orderSelRows[i].amount;
        if (!this.orderSelRows[i].selMoney)
          this.orderSelRows[i].selMoney = this.orderSelRows[i].realMoney;
      }
      for (let i = this.orderSelRows.length - 1; i >= 0; i--) {
        if (this.orderSelRows[i].isTotal) this.orderSelRows.splice(i, 1);
      }
      this.$refs.phyOrderAgGrid.gridOptions.api.setRowData(this.orderSelRows);
      //   let allColumnIds1 = [];
      //   this.$refs.phyOrderAgGrid.gridOptions.columnApi.getAllColumns().forEach(function (column) {
      //     allColumnIds1.push(column.colId);
      //   });
      //jjc20181220 注释
      //this.$refs.phyOrderAgGrid.gridOptions.columnApi.autoSizeColumns(allColumnIds1);

      this.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(
        this.createData(1, "Bottom")
      );
      this.storageDialogVisible = false;
    },
    compareDown(propertyName) {
      // 降序排序
      if (typeof this.difInfo[0][propertyName] != "number") {
        // 属性值为非数字
        return function (object1, object2) {
          var value1 = object1[propertyName];
          var value2 = object2[propertyName];
          return value2.localeCompare(value1);
        };
      } else {
        return function (object1, object2) {
          // 属性值为数字
          var value1 = object1[propertyName];
          var value2 = object2[propertyName];
          return value2 - value1;
        };
      }
    },
    cancelDialog() {
      //取消
      this.storageDialogVisible = false;
    },
    // 单元格值变化回调
    cellValueChanged(pra) {
      let that = this;
      let node = pra.node;
      this.selBillTotalAdjust = 0;
      let sumMoney = addOperation.accAdd(pra.data.realMoney, pra.newValue);
      node.setDataValue("sumMoney", sumMoney);
      this.$refs.phyStorageAgGrid.gridOptions.api.forEachNode(function (node) {
        // let col = node.columnApi.getAllDisplayedColumns();
        if (node.data.adjustMoney) {
          that.selBillTotalAdjust = addOperation.accAdd(
            node.data.adjustMoney,
            that.selBillTotalAdjust
          );
          that.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(
            that.createData(1, "Bottom")
          );
        }
      });
    },
    createData(count, prefix) {
      var result = [];
      for (let i = 0; i < count; i++) {
        let billMoney = this.selBillTotalMoney.toString().replace(/,/gi, "");
        let totalMoney = addOperation.accAdd(
          billMoney,
          this.selBillTotalAdjust
        );
        result.push({
          matName: "合计",
          isTotal: 1,
          amount: this.billTotalCount, //this.billTotalCount,
          realMoney: this.selBillTotalMoney, //this.billTotalMoney,
          adjustMoney: this.selBillTotalAdjust, //this.billTotalAdjust
          sumMoney: totalMoney
            .toString()
            .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"),
        });
      }
      return result;
    },
    createSelData(count, prefix) {
      var result = [];
      for (let i = 0; i < count; i++) {
        result.push({
          matName: "合计",
          isTotal: 1,
          amount: this.selBillTotalCount,
          realMoney: this.selBillTotalMoney,
          adjustMoney: this.selBillTotalAdjust,
        });
      }
      return result;
    },
    singleAdjustMoney(params) {
      var that = this;
      this.$confirm("是否确认调整金额？", "消息提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        distinguishCancelAndClose: true,
      })
        .then(() => {
          let lTblAdjustbill = [];
          let obj = {};
          obj.purOrdNo = params.purOrdNo;
          obj.purOrdMxNo = params.purOrdMxNo;
          obj.instockMxNo = params.instockMxNo;
          obj.instockNo = params.instockNo;
          obj.amount = params.priceAmount;
          obj.orderAmount = params.orderAmount;
          lTblAdjustbill.push(obj);
          let obj2 = {
            lTblAdjustbill: lTblAdjustbill,
          };
          _Api
            .phyAdjustMoney(obj2)
            .then(function (response) {
              let data = response.data;
              if (data.code == "1") {
                if (data.rows.length > 0) {
                  that.$refs.phyStorageAgGrid.gridOptions.api.forEachNode(
                    function (node) {
                      let rowIndex = that.$refs.phyStorageAgGrid.gridOptions.api.getRowNode(
                        node.id
                      );
                      for (let i = 0; i < data.rows.length; i++) {
                        if (data.rows[i]) {
                          if (
                            data.rows[i].purOrdNo == node.data.purOrdNo &&
                            data.rows[i].purOrdMxNo == node.data.purOrdMxNo &&
                            data.rows[i].instockNo == node.data.instockNo &&
                            data.rows[i].instockMxNo == node.data.instockMxNo
                          )
                            rowIndex.setDataValue(
                              "adjustMoney",
                              data.rows[i].diffMoney
                            );
                        }
                      }
                    }
                  );
                  //重新合计
                  if (that.storageSelRows.length > 0) {
                    let obj = {}; //合计行
                    obj.amount = 0;
                    obj.realMoney = 0;
                    obj.selBillTotalAdjust = 0;
                    for (let i = 0; i < that.storageSelRows.length; i++) {
                      obj.matName = "合计";
                      obj.amount = that.accAdd(
                        obj.amount,
                        that.storageSelRows[i].amount
                      );
                      obj.realMoney = that.accAdd(
                        obj.realMoney,
                        that.storageSelRows[i].realMoney
                      );
                      obj.selBillTotalAdjust = that.accAdd(
                        obj.selBillTotalAdjust,
                        that.storageSelRows[i].adjustMoney
                      );
                      obj.isTotal = 1;
                    }
                    //		            that.storageSelRows.push(obj);
                    that.billTotalMoney = that.accAdd(
                      obj.realMoney,
                      obj.selBillTotalAdjust
                    );
                    that.billTotalCount = obj.amount;
                    that.selBillTotalAdjust = obj.selBillTotalAdjust;
                    that.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(
                      that.createData(1, "Bottom")
                    );
                    that.$refs.phyStorageAgGrid.gridOptions.api.setRowData(
                      that.storageSelRows
                    );
                  } else {
                    that.$refs.phyStorageAgGrid.gridOptions.api.setRowData(
                      that.storageSelRows
                    );
                    that.billTotalMoney = 0;
                    that.billTotalCount = 0;
                    that.selBillTotalAdjust = 0;
                    that.$refs.phyStorageAgGrid.gridOptions.api.setPinnedBottomRowData(
                      that.createData(1, "Bottom")
                    );
                  }
                } else {
                  Msg.showSuccessMsg("该数据暂无调整记录。");
                }
              } else {
                Msg.showErrorMsg(data.info);
              }
            })
            .catch((err) => {
              Msg.showErrorMsg(err.data.message);
            });
        })
        .catch(() => {});
    },
    // 获取审批意见内容
    getAuditOptionData() {
      this.signLoading = true;
      _Api
        .getSignOption({ billNo: this.phyCode })
        .then(({ data }) => {
          this.signLoading = false;
          if (data.code == 1) {
            this.signInfo = data.rows;
          } else {
            Msg.showErrorMsg(data.info);
          }
        })
        .catch((err) => {
          this.signLoading = false;
          Msg.showErrorMsg(err.data.message);
        });
    },
    // 关闭当前tab页
    closePage() {
      this.removeTab();
    },
  },
  mounted() {
    var that = this;
    // if(this.setClickValue.flagUI == 'flowInfo'){
    //   this.setClickValue.id = this.setClickValue.orderId;
    // }
    // window.onresize = () => {
    //   return (() => {
    //     that.dialogSize = document.body.clientWidth;
    //   })();
    // }
    this.$refs.phyOrderAgGrid.gridOptions.api.hideOverlay();
    this.$refs.phyStorageAgGrid.gridOptions.api.hideOverlay();
    if (this.$global.user.userTypeId == "4") {
      supplierInfo
        .getUserInfo(this.$global.user.userName)
        .then((supplierInfo) => {
          that.supplierInfo = supplierInfo;
          if (that.supplierInfo.length > 0) {
            that.supplierName =
              that.supplierInfo[0].supplierName +
              " (" +
              that.supplierInfo[0].supplierCode +
              ")";
            that.supplierCode = that.supplierInfo[0].supplierCode;
          }
        });
      this.supplierBtnShow = true;
      this.accountBtnShow = false;
      this.adjustShow = false;
      //          this.supplierName = this.$global.user.employeeName +  " (" +  this.$global.user.userName + ")";
      //          this.getSupplierInfoByMainAccount();
    } else {
      this.supplierBtnShow = false;
      this.accountBtnShow = true;
      this.adjustShow = true;
    }
    this.getAuthInfo();
    if (this.pageLayOut == "add") {
      this.getPhysicalNo();
      serviceTime.getServiceTime().then((serviceTime) => {
        that.applyDate = serviceTime.Format("yyyy-MM-dd");
      });
      if (this.$global.user.userTypeId == "1") {
        this.btnShow = true;
      }
      this.getBtnAuth();
      this.$set(details, "isOk", true);
      this.$set(details, "adShow", false);
      this.$set(details, "billState", 1);
    } else if (this.pageLayOut == "edit" || this.pageLayOut == "view") {
      let date = Date.parse(this.setClickValue.createDate.replace(/-/g, "/"));
      this.applyDate = new Date(date).Format("yyyy-MM-dd");
      if (this.$global.user.userTypeId == "4") {
        this.labelShow = true;
        this.typeShow = true;
        this.optionShow = false;
        this.customer = this.setClickValue.companyName;
        this.selAccountCode = this.setClickValue.type;
        this.$set(details, "billState", this.setClickValue.billState);
        for (let i = 0; i < this.typeOptions.length; i++) {
          if (this.typeOptions[i].value == this.selAccountCode) {
            this.selAccountType = this.typeOptions[i].label;
            break;
          }
        }
        this.selCompanyCode = this.setClickValue;
        if (this.setClickValue.billState > 1) {
          this.inputDis = true;
          this.sendShow = false;
          this.btnShow = false;
          this.saveBtnShow = false;
          this.supplierBtnShow = false;
          this.deleteShow = false;
        } else {
          this.getBtnAuth();
        }
      } else {
        this.companyLabelShow = true;
        this.labelShow = false;
        this.typeShow = true;
        this.btnShow = false;
        this.supplierName = this.setClickValue.supplierName;
        this.supplierCode = this.setClickValue.supplierCode;
        this.selCompanyCode = this.setClickValue;
        this.selAccountCode = this.setClickValue.type;
        for (let i = 0; i < this.typeOptions.length; i++) {
          if (this.typeOptions[i].value == this.selAccountCode) {
            this.selAccountType = this.typeOptions[i].label;
            break;
          }
        }
        this.comName = this.setClickValue.companyName;
        this.optionShow = false;
        if (this.setClickValue.billState >= 2) this.deleteShow = false;
        if (this.setClickValue.billState > 1) this.inputDis = true;
        if (this.setClickValue.billState > 2) {
          this.saveBtnShow = false;
          this.supplierBtnShow = false;
          this.accountBtnShow = false;
          //   this.btnShow = false;
          this.deleteShow = false;
          this.adjustShow = false;
        }
        if (this.setClickValue.billState < 3) {
          let col = this.$refs.phyStorageAgGrid.gridOptions.columnApi.getAllDisplayedColumns();
          for (let c in col) {
            if (col[c].colId == "adjustMoney") {
              col[c].colDef.editable = () => {
                return true;
              };
            }
          }
        }
      }
      this.phyCode = this.setClickValue.gooAccNo; //实物对账编号
      this.remark = this.setClickValue.remark; //备注
      this.getGoodsDetails(this.setClickValue.gooAccNo);
      this.$set(details, "billState", this.setClickValue.billState);
      if (this.$global.user.userTypeId == "4")
        this.$set(details, "adShow", false);
      else {
        if (this.setClickValue.billState == 2)
          this.$set(details, "adShow", true);
        else this.$set(details, "adShow", false);
      }
      if (
        this.setClickValue.billState >= 2 &&
        this.$global.user.userTypeId != "4"
      ) {
        this.getBtnAuth();
      }
      this.getAuditOptionData();
    }
  },
  props: {
    pageLayOut: {
      type: String,
      default: "add",
    },
    setClickValue: {
      type: Object,
    },
    addTab: {
      type: Function,
    },
    removeTab: {
      type: Function,
    },
  },
  components: {
    upLoadfile,
    "sign-option-tab": SignOptionTab,
  },
};

Date.prototype.Format = function (fmt) {
  var o = {
    "M+": this.getMonth() + 1, //月份
    "d+": this.getDate(), //日
    "H+": this.getHours(), //小时
    "m+": this.getMinutes(), //分
    "s+": this.getSeconds(), //秒
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
    S: this.getMilliseconds(), //毫秒
  };
  if (/(y+)/.test(fmt))
    fmt = fmt.replace(
      RegExp.$1,
      (this.getFullYear() + "").substr(4 - RegExp.$1.length)
    );
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt))
      fmt = fmt.replace(
        RegExp.$1,
        RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
      );
  return fmt;
};

Number.prototype.add = function (arg) {
  return this.accAdd(arg, this);
};

function singleClickEditRenderer() {}
singleClickEditRenderer.prototype.init = function (params) {
  var template =
    '<span><button id="theValue" class="rendererClass"></button></span>';
  var tempDiv = document.createElement("div");
  tempDiv.innerHTML = template;
  this.eGui = tempDiv.firstElementChild;

  this.params = params;
  this.eValue = this.eGui.querySelector("#theValue");
  this.eValue.innerHTML = "确认"; //params.data.id;
  // this.eButton = this.eGui.querySelector("#theButton");
  this.buttonClickListener = this.onButtonClicked.bind(this);
  this.eValue.addEventListener("click", this.buttonClickListener);
};

singleClickEditRenderer.prototype.onButtonClicked = function (event) {
  //   var value = this.params.data.id;
  //app[1].__vue__.confirm(value);
  phyApp.__vue__.confirm(this.params);
};

singleClickEditRenderer.prototype.createGui = function () {};

singleClickEditRenderer.prototype.getGui = function () {
  return this.eGui;
};

singleClickEditRenderer.prototype.afterGuiAttached = function () {};

singleClickEditRenderer.prototype.destroy = function () {};

singleClickEditRenderer.prototype.isPopup = function () {
  return false;
};

function disConfirm() {}
disConfirm.prototype.init = function (params) {
  var template = '<span><label id="theValue" "></label></span>';
  var tempDiv = document.createElement("div");
  tempDiv.innerHTML = template;
  this.eGui = tempDiv.firstElementChild;

  this.params = params;
  this.eValue = this.eGui.querySelector("#theValue");
  this.eValue.innerHTML = "未确认";
};
disConfirm.prototype.createGui = function () {};

disConfirm.prototype.getGui = function () {
  return this.eGui;
};

disConfirm.prototype.afterGuiAttached = function () {};

disConfirm.prototype.destroy = function () {};

disConfirm.prototype.isPopup = function () {
  return false;
};

function isConfirm() {}
isConfirm.prototype.init = function (params) {
  var template = '<span><label id="theValue" "></label></span>';
  var tempDiv = document.createElement("div");
  tempDiv.innerHTML = template;
  this.eGui = tempDiv.firstElementChild;

  this.params = params;
  this.eValue = this.eGui.querySelector("#theValue");
  this.eValue.innerHTML = "已确认";
};
isConfirm.prototype.createGui = function () {};

isConfirm.prototype.getGui = function () {
  return this.eGui;
};

isConfirm.prototype.afterGuiAttached = function () {};

isConfirm.prototype.destroy = function () {};

isConfirm.prototype.isPopup = function () {
  return false;
};

function isZero() {}
isZero.prototype.init = function (params) {
  var template = '<span><label id="theValue" "></label></span>';
  var tempDiv = document.createElement("div");
  tempDiv.innerHTML = template;
  this.eGui = tempDiv.firstElementChild;

  this.params = params;
  this.eValue = this.eGui.querySelector("#theValue");
  this.eValue.innerHTML = "";
};
isZero.prototype.createGui = function () {};

isZero.prototype.getGui = function () {
  return this.eGui;
};

isZero.prototype.afterGuiAttached = function () {};

isZero.prototype.destroy = function () {};

isZero.prototype.isPopup = function () {
  return false;
};

function lastRowBorder(params) {
  if (params.api.rowModel.rowsToDisplay) {
    if (params.node.rowIndex == params.api.rowModel.rowsToDisplay.length - 1) {
      return { color: "red" };
    } else {
      return {};
    }
  }
}

function CustomPinnedRowRenderer() {}

CustomPinnedRowRenderer.prototype.init = function (params) {
  this.eGui = document.createElement("div");
  this.eGui.style = params.style;
  this.eGui.innerHTML = params.value;
};

CustomPinnedRowRenderer.prototype.getGui = function () {
  return this.eGui;
};
</script>

<style lang="less">
</style>